JPA/Criteria API - Like & equal problem

前端 未结 4 823
南笙
南笙 2020-12-08 00:27

I\'m trying to use Criteria API in my new project:

public List findEmps(String name) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
             


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 00:49

    I tried all the proposals and although it did not give an error, it did not recover anything if I did not put all the expected text, in the end what was proposed by user3077341 worked for me but with the variant that I use '%' instead of "%", the like worked perfect.

    List predicates = new ArrayList();
    if(reference!=null){
        Predicate condition = builder.like(root.get("reference"),'%'+reference+'%');
        predicates.add(condition);
    }
    

提交回复
热议问题