关于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);
    }//..
    

 

posted @   码海兴辰  阅读(33)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
点击右上角即可分享
微信分享提示