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注解或 ...
随机推荐
- 【洛谷 P1437】 [HNOI2004]敲砖块 (DP)
题目链接 毒瘤DP题 因为\((i,j)\)能不能敲取决于\((i-1,j)\)和\((i-1,j+1)\),所以一行一行地转移显然是有后效性的. 于是考虑从列入手.我们把这个三角形"左对齐 ...
- 平衡树之splay讲解
首先来说是splay是二叉搜索树,它可以说是线段树和SBT的综合,更可以解决一些二者解决不了的问题,splay几乎所有的操作都是由splay这一操作完成的,在介绍这一操作前我们先介绍几个概念和定义 二 ...
- [Leetcode Week5]Word Ladder II
Word Ladder II 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/word-ladder-ii/description/ Descripti ...
- Linux上使用程序相对路径访问文件【转】
转自:http://blog.csdn.net/yinxusen/article/details/7444249 今天一个朋友问我这个问题,说为什么在Windows上跑得很好的应用程序,移植到Linu ...
- Javascript传参参考
可参考的细节: <!doctype html> <html lang="en"> <head> <meta charset="U ...
- Centos安装流量监控工具iftop笔记
Centos安装流量监控工具iftop笔记 一.概述 iftop可以用来监控网卡的实时流量(可以指定网段).反向解析IP.显示端口信息等,详细的将会在后面的使用参数中说明.官方网站:http://ww ...
- text-overflow的用法
在平时的网页制作中一定碰到过内容溢出的问题,比如说文章列表很长,而其宽度又受到限制,此时超出宽度的内容就会以(...)显示.以前实现这样的效果都是由后台程序截取一定的字符数在前台输出,另外一种方法就是 ...
- Linux上安装Redis教程
Redis的安装步骤: 步骤1.安装redis必须已经安装了gcc,如果没安装gcc 就使用命令 yum install -y gcc步骤2.下载redis包 下载地址:http://download ...
- magento 开启模板路径提示
1.进入后台system->configuration->,选择main Website 2.advanced->developer中,将Debug中的Template Path H ...
- HDU 2829 Lawrence
$dp$,斜率优化. 设$dp[i][j]$表示前$i$个数字切了$j$次的最小代价.$dp[i][j]=dp[k][j-1]+p[k+1][i]$.观察状态转移方程,可以发现是一列一列推导出来的.可 ...