【问题标题】:Make part of a Cypher query dynamic with spring data neo4j 3使用 spring data neo4j 3 使 Cypher 查询成为动态的一部分
【发布时间】:2014-06-01 12:27:08
【问题描述】:

我有一个扩展 GraphRepository 的 UserRepository 类:

  public interface UserRepository extends GraphRepository<User> {

    @Query("MATCH (User:_User) WHERE User.network = {0} RETURN User")
    Iterable<User> executeFilterTest(String filterValue);

  }

问题是我并不总是确切地知道查询的“WHERE”部分会有什么。所以我希望能够将 WHERE 部分作为这样的参数发送:

    @Query("MATCH (User:_User) {0} RETURN User")
    Iterable<User> executeFilterTest(String whereValue);

有可能做这样的事情吗?或者我可以以某种方式将整个 Cypher 查询保存为字符串,然后将整个字符串作为参数发送?

【问题讨论】:

    标签: neo4j cypher spring-data spring-data-neo4j


    【解决方案1】:

    尝试使用自定义存储库示例(请注意不要认为 impl 方法必须与您的 userRepository 而不是 userRepositoryCustom 匹配,例如:UserRepositoryImpl):

    public interface UserRepository extends GraphRepository<User>, UserRepository {
    }
    
    public class UserRepositoryImpl implements UserRepositoryCustom {
        @Autowired Neo4jTemplate template;
        @Override
        public Result<Map<String, Object>> findByCypher(String cypher) {
        return template.query(cypher, null);
        }
    }
    
    public interface UserRepositoryCustom {
        Result<Map<String, Object>> findByCypher(String cypher);    
    }
    

    【讨论】:

    • UserRepository 应该扩展 UserRepositoryCustom 而不是 UserRepository
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-24
    • 1970-01-01
    • 2014-10-04
    • 2019-02-20
    • 1970-01-01
    • 2018-06-01
    相关资源
    最近更新 更多