Spring Data CrudRepository增删改查方法(八)
CrudRepository 的主要方法
long count(); boolean exists(Integer arg0); <S extends StudentPO> S save(S arg0); <S extends StudentPO> Iterable<S> save(Iterable<S> arg0); void delete(Integer arg0); void delete(Iterable<? extends StudentPO> arg0); void delete(StudentPO arg0); void deleteAll(); StudentPO findOne(Integer arg0); Iterable<StudentPO> findAll(); Iterable<StudentPO> findAll(Iterable<Integer> arg0);
1. 新建一个类 CurdEmployeeRespository 继承CrudRepository 里面实现了大量的增删改查方法
package org.springdata.repository;
import org.springdata.domain.Employee;
import org.springframework.data.repository.CrudRepository;
/**
*
*/
public interface CurdEmployeeRespository extends CrudRepository<Employee, Integer> {
}
2. 编写service实现类
package org.springdata.service;
import org.springdata.domain.Employee;
import org.springdata.repository.CurdEmployeeRespository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
/**
*/
@Service
public class CrudEmployeeService {
@Autowired
private CurdEmployeeRespository employeeRespository;
@Transactional
public void save(){
Employee employee = new Employee();
employee.setName("zhangzy");
employee.setAge(12);
employeeRespository.save(employee);
}
}
编写测试类
package org.springdata.crudservice;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springdata.repository.CurdEmployeeRespository;
import org.springdata.repository.EmployeeRepository;
import org.springdata.service.CrudEmployeeService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
*/
public class CurdServiceTest {
private ApplicationContext ctx = null;
private CrudEmployeeService crudEmployeeService = null;
@Before
public void setup(){
ctx = new ClassPathXmlApplicationContext("beans_news.xml");
crudEmployeeService = ctx.getBean(CrudEmployeeService.class);
System.out.println("setup");
}
@After
public void tearDown(){
ctx = null;
System.out.println("tearDown");
}
@Test
public void save(){
crudEmployeeService.save();
}
}
测试结果
因为我测试前把数据全部都删除了
Spring Data CrudRepository增删改查方法(八)的更多相关文章
- Django REST framework 五种增删改查方法
Django-DRF-视图的演变 版本一(基于类视图APIView类) views.py: APIView是继承的Django View视图的. 1 from .serializers impor ...
- 通用mapper的增删改查方法 留存 备忘
Mybatis通用Mapper介绍与使用 前言 使用Mybatis的开发者,大多数都会遇到一个问题,就是要写大量的SQL在xml文件中,除了特殊的业务逻辑SQL之外,还有大量结构类似的增删改查SQ ...
- Spring Ldap 的增删改查
package ldap.entity; /** * 本测试类person对象来自schema文件的core.schema文件 * objectClass为person,必填属性和可选属性也是根据该对 ...
- Spring JPA实现增删改查
1. 创建一个Spring工程 2.配置application文件 spring.datasource.driver-class-name= com.mysql.cj.jdbc.Driver spri ...
- 关于单链表的增删改查方法的递归实现(JAVA语言实现)
因为在学习数据结构,准备把java的集合框架底层源码,好好的过一遍,所以先按照自己的想法把单链表的类给写出来了; 写该类的目的: 1.练习递归 2.为深入理解java集合框架底层源码打好基础 学习的视 ...
- idea社区版+第一个spring boot项目+增删改查+yml修改端口号
参考:https://www.cnblogs.com/tanlei-sxs/p/9855071.html 中途出现问题时参考了太多 1.下载idea社区版 2.在settings -> Plug ...
- PHP历程(封装的增删改查方法)
db.class.php 主要方法 <?php /** * 数据库配置信息 */ define('DB_HOST','127.0.0.1'); //服务器 define('DB_USER', ...
- Hibernate常用增删改查方法
/** * @param obj * @return * 添加数据 */ public Serializable saveObject(Object obj){ return this.getHibe ...
- Spring Boot WebFlux 增删改查完整实战 demo
03:WebFlux Web CRUD 实践 前言 上一篇基于功能性端点去创建一个简单服务,实现了 Hello .这一篇用 Spring Boot WebFlux 的注解控制层技术创建一个 CRUD ...
随机推荐
- WPF集合
Dependency Property 依赖属性 http://www.cnblogs.com/HelloMyWorld/archive/2013/02/21/2920149.html Attache ...
- 在ubuntu下安装sourceinsight
执行更新与安装 wine: # sudo apt-get update # sudo apt-get install wine 下载SourceInsight,用wine来安装: 执行:wine so ...
- C++ 友元类,友元函数
//友元函数 友元类 #include<iostream> using namespace std; class PointB { public: friend class PointC; ...
- 23SpringMvc_各种参数绑定方式-就是<input那种
本篇博文转载自http://www.cnblogs.com/HD/p/4107674.html: SpringMVC的各种参数绑定方式 1. 基本数据类型(以int为例,其他类似):Controlle ...
- javax.Servlet的包中,属于类的是。(选择1项)
javax.Servlet的包中,属于类的是.(选择1项) A.Servlet B.GenericServlet C.ServletRequest D.ServletContext 解答:B Serv ...
- typecho篇
百度百科的介绍: Typecho是由type和echo两个词合成的,来自于开发团队的头脑风暴. Typecho基于PHP5开发,支持多种数据库,是一款内核强健﹑扩展 方便﹑体验友好﹑运行流畅的轻量级开 ...
- VC++ Debug条件断点使用
If you're trying to reproduce a rare event and getting too many false positives with your breakpoint ...
- zookeeper配置详解
原文地址: http://itindex.net/detail/40187-zookeeper-%E7%AE%A1%E7%90%86%E5%91%98-%E7%AE%A1%E7%90%86 参数名 说 ...
- 编程之美 set 8 区间重合判断
Leetcode 上有连续的两道题, 一个是 insert interval, 一个是 merge interval, 其中 insert interval 是 merge interval. 其中 ...
- C语言跳出循环
使用while或for循环时,如果想提前结束循环(在不满足结束条件的情况下结束循环),可以使用break或continue关键字. break关键字 在<C语言switch语句>一节中,我 ...