【问题标题】:spring data neo4j doesn understand dot '.' in parameterspring data neo4j 不理解 dot '.'在参数中
【发布时间】:2016-04-19 15:43:08
【问题描述】:

请帮忙解决这个问题:

@Query("MATCH (n:User{userId:1})--(friends) return friends order by {type}")
Iterable<Map<String, Object>> getLastFriendsByLevel(@Param("userId") long userId, @Param("type") String type);

type = "friends.level" 时,结果未按预期按级别排序。当参数“type”包含'.'时,似乎排序不起作用。

怎么了?

【问题讨论】:

  • 您不能参数化节点或关系属性键,您必须在查询本身中写入friends.level
  • 谢谢。 @Query("MATCH (n:User{userId:1})--(friends) 按好友顺序返回好友顺序。{type}") Iterable> getLastFriendsByLevel(@Param("userId") long userId, @Param( "type") 字符串类型) 也不起作用,当 type="level" 时?或者,有没有其他方法可以在 ordering 子句中传递参数?
  • 您的问题在当前状态下很难理解。请查看how to create a minimal, complete, and verifiable example 并编辑您的问题。
  • @DmitryRomov 您仍在尝试参数化属性键 ;-) friends 是节点,而 {type} 是属性键,这是不可能的,并且 Cypher 语言不支持。跨度>
  • 是的,我刚刚知道了)。谢谢,克里斯托夫。祝你有美好的一天!

标签: neo4j spring-data


【解决方案1】:

这可能对你有用:

@Query("MATCH (n:User{userId: {userId}})--(friends) return friends order by friends[{key}]")
Iterable<Map<String, Object>> getLastFriendsByLevel(@Param("userId") long userId, @Param("key") String key);

这个查询实际上使用userId参数,它使用key参数值(例如,“级别”)到ORDER BY那个friends键。

【讨论】:

  • 它有效。非常感谢您提出的完美不寻常的建议。它节省了很多时间。
  • 请记住始终Accept 最适合您的答案。
猜你喜欢
  • 1970-01-01
  • 2014-09-10
  • 1970-01-01
  • 2016-09-11
  • 2017-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多