Parameter in like clause JPQL

后端 未结 8 1349
盖世英雄少女心
盖世英雄少女心 2020-11-27 03:20

I am trying to write a JPQL query with a like clause:

LIKE \'%:code%\'

I would like to have code=4 and find

455
554
646
...
         


        
8条回答
  •  情书的邮戳
    2020-11-27 04:13

    1. Use below JPQL query.
    select i from Instructor i where i.address LIKE CONCAT('%',:address ,'%')");
    
    1. Use below Criteria code for the same:
    @Test
    public void findAllHavingAddressLike() {
        CriteriaBuilder cb = criteriaUtils.criteriaBuilder();
        CriteriaQuery cq = cb.createQuery(Instructor.class);
        Root root = cq.from(Instructor.class);
        printResultList(cq.select(root).where(
            cb.like(root.get(Instructor_.address), "%#1074%")));
    }
    

提交回复
热议问题