【问题标题】:String data neo4j cypher query by passing DESC or ASC as a parameter通过将 DESC 或 ASC 作为参数传递的字符串数据 Neo4j 密码查询
【发布时间】:2013-11-19 04:25:50
【问题描述】:

我有一个如下所示的 neo4j 密码查询:

@Query("START ... RETURN createDate ORDER BY createDate {2} SKIP {0} LIMIT {1}")
Iterable<SomeGraphObject> findSomeGraphObjects(int start, int offset, String sortBy);

是否可以将 DESCASC 作为参数传递给查询字符串?我正在尝试使用sortBy 参数来实现这一点。

编辑

我的完整查询:

@Query("START user=node({0}) MATCH user-[l:LIKE]->blog WHERE blog.status = 0 RETURN blog ORDER BY l.likeDate {3} SKIP {1} LIMIT {2}")
Iterable<BlogLikesData> findBlogLikesData(UserGraph userGraph, int start, int offset, String sortBy);

【问题讨论】:

    标签: cypher spring-data-neo4j


    【解决方案1】:

    据我了解您的问题,您正在寻找对数据进行排序的分页。
    在spring data neo4j中,只需使用PageRequest即可实现分页。

    @Query("START n... RETURN createDate order by n.createdDate DESC") // or ASC
    Iterable<SomeGraphObject> findSomeGraphObjects(String someparameter, Pageable pageable);  
    

    你可以打电话给findSomeGraphObjects

    obj.findSomeGraphObjects("XYZ",new PageRequest(int start, int pageSize));  
    

    更新
    我不确定,但我想保留关键字不能作为参数给出,您需要在查询中明确提及。

    【讨论】:

    • 对不起,也许我的问题不是很清楚,我不想在我的查询字符串中硬编码“DESC”,所以我设法将 sortBy 作为参数传递,在我的问题中是 {2}。
    • 啊.. 好吧,我不确定,因为我猜想保留关键字不能作为参数传递。你试过你的代码吗?结果如何?
    • 嗨阿曼,感谢您的帮助,结果如下:“org.springframework.dao.InvalidDataAccessResourceUsageException: Error execution statement START...”,我认为您是对的,这是不可能的.
    • 等等,你能提供我在@Query 块下编写的完整密码查询吗?
    • 嗨阿曼,我更新了我的问题以包含完整的密码查询字符串,感谢您的时间。
    猜你喜欢
    • 2016-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-30
    相关资源
    最近更新 更多