%Like% Query in spring JpaRepository

前端 未结 10 1669
南方客
南方客 2020-12-04 11:36

I would like to write a like query in JpaRepository but it is not returning anything :

LIKE \'%place%\'-its not working.

LIKE

10条回答
  •  南方客
    南方客 (楼主)
    2020-12-04 11:47

    The spring data JPA query needs the "%" chars as well as a space char following like in your query, as in

    @Query("Select c from Registration c where c.place like %:place%").

    Cf. http://docs.spring.io/spring-data/jpa/docs/current/reference/html.

    You may want to get rid of the @Queryannotation alltogether, as it seems to resemble the standard query (automatically implemented by the spring data proxies); i.e. using the single line

    List findByPlaceContaining(String place);
    

    is sufficient.

提交回复
热议问题