Map<String,Object> paramMap = new HashMap<String, Object>();
paramMap.put("farmid", farmid);
paramMap.put("occurDate", occurDate);
paramMap.put("producecode", producecode);
paramMap.put("buildNum", buildNum);
temperatureTimePageList = inspectionMapper.findTempPage(paramMap);
Collections.sort(temperatureTimePageList, new Comparator<TemperatureTimePage>() {
/*
* int compare(TemperatureTimePage o1, TemperatureTimePage o2) 返回一个基本类型的整型,
* 返回负数表示:o1小于o2, 返回0 表示:o1和o2相等, 返回正数表示:o1大于o2。
*/
public int compare(TemperatureTimePage o1, TemperatureTimePage o2) {
// 按照时间进行降序排列
int flag = 0;
if (null != o1.getTime()
&& null != o2.getTime()) {
flag = DateUtils.compareTime(o1.getTime(), o2.getTime());
}
if(flag == 1){
return 1;
}else if(flag == 0){
return 0;
}else{
return -1;
}
}
});
public class TemperatureTimePage {
private String time;
private String temperature;
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getTemperature() {
return temperature;
}
public void setTemperature(String temperature) {
this.temperature = temperature;
}
}
public class DateUtils {
public static int compareTime(String dateStr1,String dateStr2){
String[] str1Arr = dateStr1.split(":");
String[] str2Arr = dateStr2.split(":");
if(Integer.parseInt(str1Arr[0]) > Integer.parseInt(str2Arr[0])){
return 1;
}if(Integer.parseInt(str1Arr[0]) == Integer.parseInt(str2Arr[0])){
if(Integer.parseInt(str1Arr[1]) > Integer.parseInt(str2Arr[1])){
return 1;
}else if(Integer.parseInt(str1Arr[1]) == Integer.parseInt(str2Arr[1])){
return 0;
}else{
return -1;
}
}else{
return -1;
}
}
}