Named Query with like in where clause

天涯浪子 提交于 2019-11-30 04:30:51

You can't have the % in the NamedQuery, but you can have it in the value you assign the parameter.

As in:

String city = "needle";
query.setParamter("city", "%" + city + "%");

You can also use CONCAT function

@NamedQuery(name = "Place.getPlaceForCityAndCountryName",
     query = "SELECT p FROM Place p WHERE " +
        "lower(p.city) like CONCAT(:city,'%')");
jean
@Query("select c from Curso c where c.descripcion like CONCAT(:descripcion,'%')")

List<Curso> findByDescripcionIgnoreCase(@Param("descripcion") String descripcion);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!