Browse Source

对list中的字段remendsort进行排序

master
xyiege 4 years ago
parent
commit
ce8b89bb66
  1. 6
      README.md
  2. 14
      src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java

6
README.md

@ -69,6 +69,12 @@ eyJhbGciOiJIUzUxMiJ9.eyJhdWQiOiJCRDg0REQ0MkE3MjM0QjA1QjBDNUQxMTYxNjEzMkFDNCIsImp
23、 [Mybatis时间范围查询,亲测有效](https://www.shuzhiduo.com/A/amd0wwkj5g/)
24、 [list排序的几种方法](https://blog.csdn.net/qq_29410905/article/details/91414833)
25\ [Java实现对List中的对象按某个字段进行排序](https://blog.csdn.net/weixin_42402326/article/details/121789861)
###知识点收集:
首先使用Calendar calendar = Calendar.getInstance();//获取Calendar

14
src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java

@ -110,6 +110,20 @@ public class GoodsServiceImpl implements GoodsService {
// 排序索引
int index=0;
List<Goods> glist = goodsMapper.getGoodsByCondition(where,limit,order,"DESC");
// 查询到的list 进行排序
List<Goods> newgoodsList = new LinkedList<>();
Collections.sort(glist, new Comparator<Goods>() {
@Override
public int compare(Goods o1, Goods o2) {
if(o1.getRecommendSort()>o2.getRecommendSort()){
return -1;
}
if(o1.getRecommendSort()== o2.getRecommendSort()){
return 0;
}
return 1;
}
});
if(glist!=null){
for(Goods g:glist){
Map<String,Object> ngmap = new HashMap<>();

Loading…
Cancel
Save