简化普通模糊查询SQL
作者:
扯嘴 | 来源:发表于
2017-12-03 21:47 被阅读0次 List<Book> bookList=bookDao.findAll(new Specification<Book>() {
@Override
public Predicate toPredicate(Root<Book> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
Predicate predicate= criteriaBuilder.conjunction();
if (book!=null){
if (book.getName()!=null && !"".equals(book.getName())){
predicate.getExpressions().add(criteriaBuilder.like(root.get("name"),"%"+book.getName()+"%"));
}
if (book.getAuthor()!=null && !"".equals(book.getAuthor())){
predicate.getExpressions().add(criteriaBuilder.like(root.get("author"),"%"+book.getAuthor()+"%"));
}
}
return predicate;
}
});
本文标题:简化普通模糊查询SQL
本文链接:https://www.haomeiwen.com/subject/hbvzbxtx.html
网友评论