List<Person> peopleList = personService.getPeopleList(inputDto);
Person person = new Person();
//第一种方式
List<Person> collect = peopleList.stream().sorted(Comparator.comparing(Person::getDateTime).reversed()).collect(Collectors.toList());//对peopleList去重并排序(倒序)
if(!CollectionUtils.isEmpty(collect)){
person = collect.get(0);//取DateTime是最大的那一条数据
}
//第二种方式
List<Person> collect = peopleList.stream().collect(Collectors,collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Person::getDateTime))),ArrayList::new));//对personList排序(正序)
if(!CollectionUtils.isEmpty(collect)){
person = collect.get(collect.size()-1);//取DateTime是最大的那一条数据
}
Map<String,Object> map = new HashMap<>();
map.put("response",person);
return map;