分页

/**
* 条件查询+分页
* @param whereMap
* @param page
* @param size
* @return
*/
public Page<CaseManage> findSearch(Map whereMap, int page, int size,Integer createId) {
Sort sort = new Sort(Sort.Direction.DESC,"id");
Specification<CaseManage> specification = createSpecification(whereMap,createId);
PageRequest pageRequest = new PageRequest(page,size,sort);
return caseDao.findAll(specification, pageRequest);
} /**
* 条件查询
* @param whereMap
* @return
*/
public List<CaseManage> findSearch(Map whereMap,Integer createId) {
Specification<CaseManage> specification = createSpecification(whereMap, createId);
return caseDao.findAll(specification);
} /**
* 动态条件构建
* @param searchMap
* @return
*/
private Specification<CaseManage> createSpecification(Map searchMap,Integer createId) { return new Specification<CaseManage>() { @Override
public Predicate toPredicate(Root<CaseManage> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> predicateList = new ArrayList<Predicate>();
// 案件名称
if (searchMap.get("case_name")!=null && !"".equals(searchMap.get("case_name"))) {
predicateList.add(cb.like(root.get("case_name").as(String.class), "%"+(String)searchMap.get("case_name")+"%"));
}
// 案件编号uuid类型
if (searchMap.get("case_uuid")!=null && !"".equals(searchMap.get("case_uuid"))) {
predicateList.add(cb.equal(root.get("case_uuid").as(String.class), (String)searchMap.get("case_uuid")));
}
return cb.and( predicateList.toArray(new Predicate[predicateList.size()])); }
}; }

or查询

想实现这样的效果

where (state=1 or state=2)and name='zhangsan'

java代码

List<Predicate> predicateList = new ArrayList<Predicate>();
Predicate or = cb.or(cb.and(cb.equal(root.get("case_authority").as(String.class), "0")), cb.and(cb.equal(root.get("create_id").as(String.class), String.valueOf(createId))));
predicateList.add(or);

最新文章

  1. 【半原创】将js和css文件装入localStorage加速程序执行
  2. 利用spring自己实现观察者模式
  3. 我见过的 Objective-C, 讲的最通俗易懂的入门教程....
  4. linq中的contains条件
  5. MySql 在大数量的统计中具体的使用技巧
  6. 【CF】323 Div2. D. Once Again...
  7. Morris Traversal 二叉树遍历。
  8. 定义一个栈的数据结构,要求实现一个min函数,每次能够得到栈的最小值,并且要求Min的时间复杂度为O(1)
  9. ASP.NET MVC进阶之路:依赖注入(Di)和Ninject
  10. js动态设置输入框字体/颜色
  11. 对于任意大于1的自然数n,若n为奇数,则将n变为3n+1,否则变为n的一半。 经过若干次这样的变换,一定会使n变为1
  12. 用DataRelation给多个DataTable建立关系并显示到TreeView
  13. 路飞学城-Python开发集训-第3章
  14. Jquery 获取radio选中值
  15. offset[Parent/Width/Height/Top/Left] 、 client[Width/Height/Top/Left] 、 Element.getBoundingClientRect()
  16. BAT等公司必问的8道Java经典面试题,你都会了吗?
  17. BZOJ 2843: 极地旅行社 lct splay
  18. scala mapPartitionsWithIndex函数的使用
  19. Effective java笔记3--类和接口2
  20. SQL语法:MySQL系列之四

热门文章

  1. centos安装桌面,下面的几个包缺一不可
  2. JPA save新增问题
  3. 洛谷P1092 虫食算(算竞进阶习题)
  4. [HDU4635] Strongly connected
  5. 【hdu6186】CS Course(前缀后缀异或)
  6. 自学Zabbix4.0之路
  7. 【APIO2018】新家(线段树)
  8. [luogu4139]上帝与集合的正确用法【欧拉定理+扩展欧拉定理】
  9. [luogu4072][bzoj4518][SDOI2016]征途【动态规划+斜率优化】
  10. html标题、段落、换行与字符实体