Use Springboot to write a complex query with only one condition.

Write on Dao implementation layer or manager level.

default List<BbwBarrage> findByEnable(int enable) {

return this.findAll(new Specification<BbwBarrage>() {
@Override
public Predicate toPredicate(Root<BbwBarrage> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
Predicate predicate;
// TODO Auto-generated method stub
Path enableP = root.get(“enable”);

predicate = criteriaBuilder.equal(enableP, enable);

query.where(predicate);

return predicate;
}
});
}

 

 

Directly in the controller layer

List<T> lists = xxManager.finaAll(xx);

 

Paging query is also the routine.

Leave a Reply

Your email address will not be published. Required fields are marked *