Spring-data-jpa 之Specification in的用法
1.一个简单的 Predicate 的示例
构建简单的Predicate示例:
Predicate p1=cb.like(root.get(“name”).as(String.class), “%”+uqm.getName()+“%”);
Predicate p2=cb.equal(root.get("uuid").as(Integer.class), uqm.getUuid());
Predicate p3=cb.gt(root.get("age").as(Integer.class), uqm.getAge());
构建组合的Predicate示例:
Predicate p = cb.and(p3,cb.or(p1,p2));
2.in 用法实例
//根据竞买人客户名称进行查询
In<Long> in = cb.in(root.get(BailPay_.customerId)); if(customerName != null && !customerName.isEmpty()){
List<Customer> customerList = customerRepository.findAllByCustomerName(customerName);
if (customerList != null && customerList.size()>0) {
for (Customer customer : customerList) {
if (customer != null) {
in.value(customer.id());
}
}
predicates.add(in);
}else{
Predicate predicateCustomerId = cb.equal(root.get(BailPay_.customerId), 0L);
predicates.add(predicateCustomerId);
}
}
3.今天总结这种做法的目的是,项目中碰上了匹配不定个数的条件的需求,使用cb.or 存在各种各样的问题。
Spring-data-jpa 之Specification in的用法的更多相关文章
- spring data jpa封装specification实现简单风格的动态查询
github:https://github.com/peterowang/spring-data-jpa-demo 单一实体的动态查询: @Servicepublic class AdvancedUs ...
- 使用Spring Data JPA的Specification构建数据库查询
Spring Data JPA最为优秀的特性就是可以通过自定义方法名称生成查询来轻松创建查询SQL.Spring Data JPA提供了一个Repository编程模型,最简单的方式就是通过扩展Jpa ...
- Spring Data Jpa:分页、Specification、Criteria
分页的主要接口与类 PagingAndSortingRepository 继承自 CrudRepository 接口,提供了排序以及分页查询能力,提供了两个方法 Iterable<T> f ...
- 解决neo4j @Transactional 与Spring data jpa @Transactional 冲突问题,@CreatedBy,@CreatedDate,@LastModifiedBy,@LastModifiedDate,以及解决@Version失效问题
之前mybatis特别流行,所以前几个项目都是用@SelectProvider,@InsertProvider,@UpdateProvider,@DeleteProvider 加反射泛型封装了一些通用 ...
- Spring Data JPA系列3:JPA项目中核心场景与进阶用法介绍
大家好,又见面了. 到这里呢,已经是本SpringData JPA系列文档的第三篇了,先来回顾下前面两篇: 在第1篇<Spring Data JPA系列1:JDBC.ORM.JPA.Spring ...
- spring data jpa @query的用法
@Query注解的用法(Spring Data JPA) 参考文章:http://www.tuicool.com/articles/jQJBNv . 一个使用@Query注解的简单例子 @Query( ...
- Spring data jpa 实现简单动态查询的通用Specification方法
本篇前提: SpringBoot中使用Spring Data Jpa 实现简单的动态查询的两种方法 这篇文章中的第二种方法 实现Specification 这块的方法 只适用于一个对象针对某一个固定字 ...
- spring data jpa Specification动态查询
package com.ytkj.entity; import javax.persistence.*; import java.io.Serializable; /** * @Entity * 作用 ...
- Spring Data Jpa简单了解
原文来源:http://www.cnblogs.com/xuyuanjia/p/5707681.html 以下是自己简单整理原有文章,其实就是在原来文章基础上化重点以及可能会有所删减的方式进行整理,需 ...
- Spring Data JPA 初体验
一,JPA相关的概念 JPA概述 全称是:JavaPersistence API.是SUN公司推出的一套基于ORM的规范. Hibernate框架中提供了JPA的实现. JPA通过JDK 5.0注解或 ...
随机推荐
- vc6.0里使用lib(静态库)的方法
vc6.0 中使用lib文件 使用库的方法如下:1. 包含库的头文件(把库的头文件包含到项目中)在应用程序工程中使用#include "file path"file path可以为 ...
- PHP正则经典漏洞
@author: Dlive P牛在小密圈中发的一个有关使用PHP正则配合写配置文件导致Getshell的经典漏洞 漏洞代码是这样的: <?php //ph.php $str = addslas ...
- java中 快捷键输入System.out.println();
syso 然后:alt+ /(就是问号键)
- 出现“error c4430缺少类型说明符-假定为int。注意C++不支持默认int
出现这种错误的原因,是因为函数没有写返回值.是在VC6.0的工程转为高版本(VS2010)的时候经常出现的; #include <stdio.h> main() { printf(&quo ...
- python批量下载淘宝图片3
import urllib.request import os def url_open(url): req = urllib.request.Request(url) req.add_header( ...
- solr params.json
The Request Parameters API allows creating parameter sets that can override or take the place of par ...
- 执行监听器( Execution listener)
相关类: org.activiti.engine.delegate.ExecutionListener org.activiti.engine.delegate.TaskListener org.ac ...
- 学习OpenResty编程
1.Windows版本的下载位置 https://github.com/LomoX-Offical/nginx-openresty-windows Linux下OpenResty的下载和安装 http ...
- POSTGRESQL 完美备份还原
1.POSTGRESQL 完美备份还原 进入到Postgresql下的bin文件夹,会看到不少的exe文件,这就是PostgreSQL内置的工具了.里面会找到pg_dump.exe.我们实际使用的就是 ...
- 关于Promise 简单使用理解
在学一个新的知识的时候,我的总结是首先要具备相关的基础知识,其次就是可以静下心来能看进去去理解,看一两遍不懂,就看四五遍,甚至六七遍,每一遍都认真努力理解,总会学会的. Promise是一个构造函数, ...