jpa常用的增删查
来源:互联网 发布:mac机械硬盘开机速度 编辑:程序博客网 时间:2024/04/28 00:40
package com.springboot.in.action.daoimport java.util.Listimport com.springboot.in.action.entity.HttpApiimport org.springframework.data.jpa.repository.Queryimport org.springframework.data.repository.CrudRepositoryimport scala.language.implicitConversionstrait HttpApiDao extends CrudRepository[HttpApi, Integer] {//查询所有数据 def findAll(): List[HttpApi] // JavaConversions//保存 def save(t: HttpApi): HttpApi//查找根据ID查询 def findOne(id: Integer): HttpApi//根据实体属性查询findByProperty(type property)条件查询 and/or/findByAgeLessThan/LessThanEqual 等,总数 查询 count() 或者 根据某个属性的值查询总数countByAge(int age);删除: delete() 或者 deleteByProperty 例如:deleteByAge(int age) ;更新(1):@Modifying@Query("update Customer u set u.age = ?1 where u.id = ?2")int update(int age1 , long id);更新(2):@Modifying@Query("update Customer u set u.age = :age where u.id = :id")int update(Param("age ")int age1 , Param("id")long id);@Query(value = "SELECT * FROM http_api where http_suite_id = ?1", nativeQuery = true) def listByHttpSuiteId(id: Integer): List[HttpApi] @Query(value = "SELECT id FROM http_api where http_suite_id = ?1", nativeQuery = true) def listTestCaseId(httpSuiteId: Integer): List[Integer] // 隐式转换,直接用scala的List会报错:javax.persistence.NonUniqueResultException: result returns more than one elements] with root cause @Query(value = "SELECT * FROM http_api where name like %?1% ", nativeQuery = true) // like '%?%' def findByName(name: String): List[HttpApi] @Query(value = "select count(*) from http_api where http_suite_id = ?1 and state = 1", nativeQuery = true) def countPass(httpSuiteId: Integer): Int @Query(value = "select count(*) from http_api where http_suite_id = ?1 and state = 0", nativeQuery = true) def countFail(httpSuiteId: Integer): Int}
- //And --- 等价于 SQL 中的 and 关键字,比如 findByHeightAndSex(int height,char sex);
- public List<User> findByHeightAndSex(int height,char sex);
- // Or --- 等价于 SQL 中的 or 关键字,比如 findByHeightOrSex(int height,char sex);
- public List<User> findByHeightOrSex(int height,char sex);
- //Between --- 等价于 SQL 中的 between 关键字,比如 findByHeightBetween(int min, int max);
- public List<User> findByHeightBetween(int min,int max);
- //LessThan --- 等价于 SQL 中的 "<",比如 findByHeightLessThan(int max);
- public List<User> findByHeightLessThan(int max);
- //GreaterThan --- 等价于 SQL 中的">",比如 findByHeightGreaterThan(int min);
- public List<User> findByHeightGreaterThan(int min);
- //IsNull --- 等价于 SQL 中的 "is null",比如 findByNameIsNull();
- public List<User> findByNameIsNull();
- //IsNotNull --- 等价于 SQL 中的 "is not null",比如 findByNameIsNotNull();
- public List<User> findByNameIsNotNull();
- //NotNull --- 与 IsNotNull 等价;
- public List<User> findByNameNotNull();
- //Like --- 等价于 SQL 中的 "like",比如 findByNameLike(String name);
- public List<User> findByNameLike(String name);
- //NotLike --- 等价于 SQL 中的 "not like",比如 findByNameNotLike(String name);
- public List<User> findByNameNotLike(String name);
- //OrderBy --- 等价于 SQL 中的 "order by",比如 findByNameNotNullOrderByHeightAsc();
- public List<User>findByNameNotNullOrderByHeightAsc();
- //Not --- 等价于 SQL 中的 "! =",比如 findByNameNot(String name);
- public List<User> findByNameNot(String name);
- //In --- 等价于 SQL 中的 "in",比如 findByNameIN(String name);
- public List<User> findByNameIn(String name);
- //NotIn --- 等价于 SQL 中的 "not in",比如 findByNameNotIN(String name);
- public List<User> findByNameNotIn(String name);
jpa 复杂查询
http://blog.csdn.net/yingxiake/article/details/51014223
阅读全文
0 0
- jpa常用的增删查
- JBOSS+JPA的增删改查操作
- JPA增删改查
- JPA客户端增删改查
- Springboot 之 JPA对Mysql数据库的增删改查
- hibernate的增删改查EntityManager怎么注入JPA @PersistenceContext
- hibernate+JPA实现对数据库的增删改查
- GridView中常用的增删改查
- sqlite常用的命令-增删改查
- 常用的oracle增删改查语句
- 常用的增删改查函数
- mysql的增删改查常用语法
- sqlite常用的命令-增删改查
- oracle常用的增删改查
- 一步步实现:JPA的基本增删改查CRUD(jpa基于hibernate)
- Spring Data JPA 增删改查
- jpa数据库增删改查基本操作
- Hibernate中JPA的简单使用,实现简单的对表的增删改查操作
- AI Challenger 2017 决赛暨颁奖礼全球直播
- sass 上下边框1像素实现
- BioSolveIT SeeSAR.v7.1
- 短文本情感分析
- 在导入build.gradle时的注意事项
- jpa常用的增删查
- vuejs中使用element UI 时间选择器和下拉框选择器的问题
- splay
- 020Valid Parentheses
- mysql新增时存在更新
- hdfs上复杂的json格式文件存入hbase,求大神。。。。。
- Scala学习笔记——主构造器、辅助构造器与私有构造器
- R语言︱SNA-社会关系网络—igraph包(中心度、中心势)(二)
- python核心编程第二版第四章学习笔记