取数据库表中最新的一条数据
2020-04-08 本文已影响0人
你好赵大宝
数据库结构:
id | suite_rank | user_rank | monitor_time |
---|---|---|---|
1 | 23 | 34 | 20200109 |
2 | 42 | 68 | 20200209 |
将数据库中数据按照时间顺序正序排列:
Collections.sort(models, new Comparator<JobDayDtoBean>() {
@Override
public int compare(JobDayDtoBean o1, JobDayDtoBean o2) {
return o1.getMonitorTime().getTime() == o2.getMonitorTime().getTime() ? 0 : (o1.getMonitorTime().getTime() < o2.getMonitorTime().getTime() ? 1 : -1);
}
});
List的排序方法:
Collections.sort(List<>,new Comparetor)
Collections.reverse(List<>)