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 ...
随机推荐
- 容易造成JavaScript内存泄露几个方面
高效的JavaScript Web应用必须流畅,快速.与用户交互的任何应用程序,都需要考虑如何确保内存有效使用,因为如果消耗过多,页面就会崩溃,迫使用户重新加载.而你只能躲在角落哭泣. 自动垃圾收集是 ...
- python模块:xlsxwriter和xlrd相结合读取
python模块简单说明: xlsxwriter:负责写入数据 xlrd:负责读取数据 xlsxwriter 官方文档:http://xlsxwriter.readthedocs.org 本实例是刚写 ...
- 基于Gitolite的Git服务架设
如果不是要与他人协同开发,git根本不需要架设服务器,git可以直接使用本地版本库的路径完成git版本间的操作.但是如果需要和他人分享版本库,协作开发,就需要能够通过网络协议操作git库.git支持的 ...
- 除去Scala的糖衣(13) -- Default Parameter Value
欢迎关注我的新博客地址:http://cuipengfei.me/ 好久没有写博客了,上一次更新竟然是一月份. 说工作忙都是借口,咋有空看美剧呢. 这半年荒废掉博客说到底就是懒,惯性的懒惰.写博客这事 ...
- 树形dp - Codeforces Round #322 (Div. 2) F Zublicanes and Mumocrates
Zublicanes and Mumocrates Problem's Link Mean: 给定一个无向图,需要把这个图分成两部分,使得两部分中边数为1的结点数量相等,最少需要去掉多少条边. ana ...
- PHP 汉字转成拼音
<?php class ZH{ /** * 将字符串转化为拼音 */ function Pinyin($_String, $_Code='gb2312') { $_DataKey =" ...
- 在Javascript弹出窗口中输入换行符
private void showMessage(string strMsg) { Page.RegisterStartupScript("scriptStr", "&l ...
- 动态加载javascript增强版
我们经常使用动态加载Javascript,写个函数很容易现实,之前也写过一个函数,不过当加载多个JS时,只能根据浏览器返回的顺序来先后加载,这肯定不是我们想要的,现在使用了一下技巧,当加载多个JS时, ...
- mongodb和redis设计原理简析
转自:http://blog.csdn.net/yangbutao/article/details/8309539 redis: 1.NIO通信 因都在内存操作,所以逻辑的操作非常快,减少 ...
- 【BZOJ】1072: [SCOI2007]排列perm(状压dp+特殊的技巧)
http://www.lydsy.com/JudgeOnline/problem.php?id=1072 首先无限膜拜题解orz表示只会暴力orz 数据那么小我竟然想不到状压! orz 这种题可以取模 ...