Kat*_*a L 3 hibernate jpa hql spring-data
我想写一个这样的查询
@Query("select p from Product p where p.name = ?1 or p.desc like %?1%")
Run Code Online (Sandbox Code Playgroud)
但它给了我例外
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: % near line 1,
Run Code Online (Sandbox Code Playgroud)
我尝试用 '%' 替换 % 或像这样连接查询字符串:“select ... like '%'” + "?1" + "'%'" 但没有运气,请帮助我
如果您使用的是 Spring Data JPA 版本 1.3.1 或更高版本,则需要执行以下操作:
@Query("select p from Product p where p.name = :name or p.desc like %:name%")
public List<Product> searchByName(@Param("name") String name);
Run Code Online (Sandbox Code Playgroud)
查看此博客文章了解更多详情
在 Spring Data JPA 1.3.1 之前,您不能%在 @Query 注释中使用,而是需要将它添加到参数本身中
| 归档时间: |
|
| 查看次数: |
9255 次 |
| 最近记录: |