【java】java8排序

目录

  • 需求
  • 实现
  • 注意

需求

查询出一个list,我要按状态和创建时间排序,为什么不在数据库直接排好序呢?因为我的状态我重新赋值了,数据库中没有对应的字段,同时也不是一个SQL所能解决的业务。可以理解拼接啦

实现

// 按状态排序
    List<Info> projectInfoList = InfoList.stream()
        .sorted(Comparator.comparing(Info::getCreated_at).reversed())
        .sorted(Comparator.comparing(Info::getProStatus))
        .collect(Collectors.toList());
    response.setPatientCheckProjectInfos(projectInfoList);

//InfoList 是我从后端已查询好的List,根据它按Created_at ProStatus排序
//reversed() 降序

注意

// 我是按状态 0待确认 1进行中 2已结束 3已拒绝排序(升序),然后再按待确认最新时间排序(降序)
// 先排时间 再排状态

你可能感兴趣的:(_______【后端】)