关于list冒泡排序+对象里面时间转时间戳进行比较
1.一个是对象里面的时间转时间戳
2.然后用冒泡排序进行时间戳值的比较
3.通过比较大小交换集合里面的对象进行排序
//获得列表结果查询
@RequestMapping(value = "/feelist",method = RequestMethod.GET)
@ResponseBody
public ApiResponseResult feelist( long hotelId,String roomNo){
Hotel h = hotelService.getHotel(hotelId);
FeeMonth f=new FeeMonth();
f.setHotel(h);
f.setRoomNo(roomNo);
List<FeeMonth> feelist =feeMonthService.FeeMonthgz(f);
if(feelist==null || feelist.size()<1){
return ApiResponseResult.failure("没有记录", -1);
}
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
for(int i=0;i<feelist.size()-1;i++){//外层循环控制排序趟数
for(int j=0;j<feelist.size()-1-i;j++){//内层循环控制每一趟排序多少次
try {
if((simpleDateFormat.parse(feelist.get(j).getDatemonth())).getTime()>(simpleDateFormat.parse(feelist.get(j+1).getDatemonth())).getTime()){
FeeMonth fee=feelist.get(j);
feelist.set((j), feelist.get(j+1));
feelist.set((j+1), fee);
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return ApiResponseResult.success().data(feelist);
}//..
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统