我有两个分页和排序数据的解决方案。
1)我可以创建一个Mongo查询,它将为我创建分页和排序。 ( 2)我可以获取所有的数据,并使用流先进行排序,而不是在其上应用分页。
主要议题
我必须对字符串进行一些自定义排序,并对mongo不提供的忽略大小写AlphaNumeric排序。我现在有一个解决方案,只是为了忽略这个丑陋的案子。(我也能找到某种东西)
如果我从Db获取所有记录并编写任何比较器并对记录进行排序,并且不使用流api应用分页,我就可以很容易地实现这种排序。
性能指南需要
哪一种选择更合适,也不那么复杂?或者哪种选择仍然是最好的呢?
发布于 2020-05-22 16:11:11
public static Stream<String[]> fetchDispLst(String[][] items, int sortParam ,int sortOrder ,int itemsPerPage ,int pageNo ) {
List<String[]> strmlist = Stream.of(items).sorted((first,second)-> {
if (sortOrder == 0) {
final String time1 = first[sortParam];
final String time2 = second[sortParam];
int compare = time1.compareTo(time2);
if(compare != 0){
return compare;
}
return compare;
}else {
final String time1 = first[sortParam];
final String time2 = second[sortParam];
int compare = time2.compareTo(time1);
if(compare != 0){
return compare;
}
return compare;
}
}).collect(Collectors.toList());
return strmlist.subList((pageNo - 1) * itemsPerPage , strmlist.size()).stream();
}https://stackoverflow.com/questions/47589278
复制相似问题