比如说我有以下设置,
像这样的模型:
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,但它不起作用。