jpa常用的增删查

 

package com.springboot.in.action.dao import java.util.List import com.springboot.in.action.entity.HttpApi import org.springframework.data.jpa.repository.Query import org.springframework.data.repository.CrudRepository import scala.language.implicitConversions trait 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 }

 
 
  1. //And --- 等价于 SQL 中的 and 关键字,比如 findByHeightAndSex(int height,char sex);  
  2.  public List<User> findByHeightAndSex(int height,char sex);  
  3.   
  4. // Or --- 等价于 SQL 中的 or 关键字,比如 findByHeightOrSex(int height,char sex);  
  5.  public List<User> findByHeightOrSex(int height,char sex);  
  6.   
  7.  //Between --- 等价于 SQL 中的 between 关键字,比如 findByHeightBetween(int min, int max);  
  8.  public List<User> findByHeightBetween(int min,int max);  
  9.   
  10.  //LessThan --- 等价于 SQL 中的 "<",比如 findByHeightLessThan(int max);  
  11.  public List<User> findByHeightLessThan(int max);  
  12.   
  13.  //GreaterThan --- 等价于 SQL 中的">",比如 findByHeightGreaterThan(int min);  
  14.  public List<User> findByHeightGreaterThan(int min);  
  15.   
  16.  //IsNull --- 等价于 SQL 中的 "is null",比如 findByNameIsNull();  
  17.  public List<User> findByNameIsNull();  
  18.   
  19.  //IsNotNull --- 等价于 SQL 中的 "is not null",比如 findByNameIsNotNull();  
  20.  public List<User> findByNameIsNotNull();  
  21.   
  22.  //NotNull --- 与 IsNotNull 等价;  
  23.  public List<User> findByNameNotNull();  
  24.   
  25.  //Like --- 等价于 SQL 中的 "like",比如 findByNameLike(String name);  
  26.  public List<User> findByNameLike(String name);  
  27.   
  28.  //NotLike --- 等价于 SQL 中的 "not like",比如 findByNameNotLike(String name);  
  29.  public List<User> findByNameNotLike(String name);  
  30.   
  31.  //OrderBy --- 等价于 SQL 中的 "order by",比如 findByNameNotNullOrderByHeightAsc();  
  32.  public List<User>findByNameNotNullOrderByHeightAsc();  
  33.   
  34.  //Not --- 等价于 SQL 中的 "! =",比如 findByNameNot(String name);  
  35.  public List<User> findByNameNot(String name);  
  36.   
  37.  //In --- 等价于 SQL 中的 "in",比如 findByNameIN(String name);  
  38.  public List<User> findByNameIn(String name);  
  39.   
  40.  //NotIn --- 等价于 SQL 中的 "not in",比如 findByNameNotIN(String name);  
  41.  public List<User> findByNameNotIn(String name);  

jpa 复杂查询

http://blog.csdn.net/yingxiake/article/details/51014223

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值