【问题标题】:search phrase string using jpa queries使用 jpa 查询搜索短语字符串
【发布时间】:2017-05-30 19:23:06
【问题描述】:

我使用这样的 Spring Data 使用 JPA 查询进行搜索:

我的接口仓库:

public interface AnnonceDao extends   JpaRepository<Annonce, Integer> {
    Page<Annonce> findByTitreContaining(String titre,Pageable page);
}

当我寻找像 Hello Friend 这样的东西时,我得到了所有已连接 Hello Friend 的实体,我也想要得到 Friend Hello 或任何包含 的实体>你好朋友。我可以用作查询,感谢您的帮助。

【问题讨论】:

    标签: spring-data


    【解决方案1】:

    这应该可行:

    public interface AnnonceDao extends   JpaRepository<Annonce, Integer> {
        Page<Annonce> findByTitreContainingAndTitreContaining(
            String part1, 
            String part2,
            Pageable page
        );
    }
    

    如果在编译时您要传递的术语数未知,正如您在评论中解释的那样,您可以使用Specifications

    这将创建规范的任务留给存储库的客户端。如果您不喜欢这样,您可以提供自定义方法并在其中动态创建查询。同样,您可以选择多种技术:

    • SQL
    • JQL
    • 查询Dsl

    QueryDsl looks actually really nice 并且可读,如链接示例中所示。

    【讨论】:

    • 感谢 Jens 的回答,实际上字数是已知的,这是一种搜索,所以我的字符串中没有字数。
    猜你喜欢
    • 2020-01-27
    • 1970-01-01
    • 1970-01-01
    • 2013-08-07
    • 2012-08-12
    • 2021-07-24
    • 1970-01-01
    • 2015-11-11
    • 2023-03-11
    相关资源
    最近更新 更多