【发布时间】:2020-04-22 14:27:46
【问题描述】:
比如说我有以下设置,
这样的模型:
public class Post {
@Id
private String id;
private String post;
private List<Vote> votes = new ArrayList<>();
// Getters & Setters...
public double getUpVotes() {
return votes.stream().filter(vote -> vote.getDirection() == 1).mapToInt(Vote::getDirection).count();
}
}
和
public class Vote {
private short direction;
// Getters & Setters...
}
然后是这样的存储库
@Repository
public interface PostRepository extends PagingAndSortingRepository<Post, String> {
List<Post> findAll(Pageable pageable);
}
并说我想通过getter方法getUpVotes()的结果对帖子进行排序
我尝试了以下localhost:3005/opinion?page=0&size=20&sort=upVotes,但它不起作用。
【问题讨论】:
标签: java mongodb spring-boot repository pageable