public List queryIpaddress(String queryParam) {
List<Map<String, String>> list = JSONUtil.getBeanFromJSONString(queryParam);
List<Map<String, String>> list1 = ipAccessDao.queryIpaddress(list);
System.out.print(list1);
//匿名实现Comparator接口进行排序,对List<Map>排序
Collections.sort(list1,new Comparator<Map<String,String>>() {
public int compare(Map<String, String> o1,Map<String, String> o2) {
//o1,o2是list中的Map,可以在其内取得值,按其排序,此例为升序,s1和s2是排序字段值
int s1 = Integer.parseInt(o1.get("IP_D").toString()) ;
int s2 = Integer.parseInt(o2.get("IP_D").toString()) ;
if(s1>s2) {
return 1;
}else {
return -1;
}
}
});
return list1;
}
转载于:https://my.oschina.net/zxj143/blog/899957