%Like Spring JpaRepository中的%Query [英] %Like% Query in spring JpaRepository

查看:374
本文介绍了%Like Spring JpaRepository中的%Query的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 JpaRepository 中写一个类似的查询,但它没有返回任何内容:

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

LIKE'%place%' -its not working。

LIKE '%place%'-its not working.

LIKE'place'效果很好。

这是我的代码:

@Repository("registerUserRepository")
public interface RegisterUserRepository extends 
JpaRepository<Registration,Long>{

    @Query("Select c from Registration c where c.place like:place")
     List<Registration> findByPlaceContaining(@Param("place")String place);
}


推荐答案

Spring数据JPA查询需要查询中的%字符以及之后的空格字符,如

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

@Query(从注册c中选择c,其中c.place如%:place%)

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

您可能希望完全删除 @Query 注释,如它似乎类似于标准查询(由spring数据代理自动实现);即使用单行

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<Registration> findByPlaceContaining(String place);

就足够了。

这篇关于%Like Spring JpaRepository中的%Query的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆