【问题标题】:SDN4 - cannot orderBy object from repositorySDN4 - 无法从存储库中订购对象
【发布时间】:2016-12-05 03:15:44
【问题描述】:

更新到 Spring Data Neo4j 4.1.3 RELEASE 后,我无法使用 OrderBy。例如我调用 findByIdOrderByNoAsc(String id)

我需要使用解决方法并为此创建一个 Collection.sort 方法。在 Spring Data Neo4j 3 中仍然可以正常工作,但更新后,我才意识到我的对象列表没有按升序或降序排列。

这是我的存储库:

package com.sample.repository;

import java.util.List;

import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.GraphRepository;

import com.sample.model.Item;

public interface ItemRepository extends GraphRepository<Item> {

    Item findByIdOrderByNoAsc(String id);

}

SDN4已经不支持这种功能了吗?如何在不使用 Pageable 的情况下对存储库中的对象进行排序?

【问题讨论】:

    标签: java spring neo4j spring-data spring-data-neo4j-4


    【解决方案1】:

    SDN 4 尚不支持派生查找器的静态 *orderBy,但您可以使用 org.springframework.data.domain.Sort 直到它被支持

    例如

    List&lt;Cinema&gt; findByLocation(String city, Sort sort);

    【讨论】:

    • 所以我只是在我的方法中添加了 Sort 参数?像这样: Item findByIdOrderByNoAsc(String id, Sort sort);并输入 new Sort(Direction.ASC) 或 new Sort(Direction.DESC) ?
    • 对参数是,但不要将 OrderByNoAsc 放在您的方法名称中。应该是 findById(String id, Sort sort)
    猜你喜欢
    • 2015-11-04
    • 1970-01-01
    • 2010-12-09
    • 2018-01-31
    • 2021-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多