@Query annotation using like %?1%

前端 未结 2 1333
不思量自难忘°
不思量自难忘° 2021-01-14 04:46

I\'d like to write a query like this

@Query(\"select p from Product p where p.name = ?1 or p.desc like %?1%\")

but it gives me the exceptio

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-14 05:30

    If you are using Spring Data JPA version 1.3.1 or later you need to do the following:

    @Query("select p from Product p where p.name = :name or p.desc like %:name%")
    public List searchByName(@Param("name") String name);
    

    Check out this blog post for more details

    Prior to Spring Data JPA 1.3.1, you could not use % in the @Query annotation, but instead you needed to add it in the argument itself

提交回复
热议问题