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 ...
随机推荐
- echarts 百度图表
手册说明 http://echarts.baidu.com/option.html 3.0版本加了很多新属性可以看以上链接 此文用的3.x版本 第一步 引入 <script src=" ...
- 等边三角形---dfs
蒜头君手上有一些小木棍,它们长短不一,蒜头君想用这些木棍拼出一个等边三角形,并且每根木棍都要用到. 例如,蒜头君手上有长度为 11,22,33,33 的4根木棍,他可以让长度为11,22 的木棍组成一 ...
- windows测试模式
测试模式通常意义就是让windows 操作系统在测试状态下运行,windows操作系统在这种模式下可以运行非官方或无数字签名的驱动程序 . 目录 1 定义 2 进入/退出windows测试模式方法 ...
- WP8持续集成之通过命令行跑单元测试
理论基础 对于如何在WP8上创建单元测试工程,在这里首先提供一个MSDN的文档作为参考. http://msdn.microsoft.com/en-us/library/windowsphon ...
- 一款纯css3实现的发光屏幕旋转特效
今天给大家带来一款纯css3实现的发光屏幕旋转特效.该屏幕由纯css3实现带发光旋转特效,效果图如下: 在线预览 源码下载 实现的代码. html代码: <div class="s ...
- 通过Hadoop安全部署经验总结,开发出以下十大建议,以确保大型和复杂多样环境下的数据信息安全。
通过Hadoop安全部署经验总结,开发出以下十大建议,以确保大型和复杂多样环境下的数据信息安全. 1.先下手为强!在规划部署阶段就确定数据的隐私保护策略,最好是在将数据放入到Hadoop之前就确定好保 ...
- mysql -- 创建存储过程 往数据表中新增字段
需求: 往某数据库的某个表中新增一个字段(若该字段已存在,则不做操作:若该字段不存在,则新增) 百度了n久,没有符合要求的例子,只有参考加自己琢磨,最终终于给弄出来了,以下是几个版本的更迭 第一版: ...
- jquery设置cors跨域
老版写法 $.support.cors = true; 新版写法 crossDomain: true
- c#用run32dll打开系统dll(如系统图片查看器,并置最顶层)
[DllImport("user32.dll", EntryPoint = "SetWindowPos",CharSet = CharSet.Auto)] st ...
- VC++分页打印实现
VC++分页打印实现: C++ Code 12345678910111213141516171819202122232425262728293031323334353637383940414243 ...