返回我使用LinkedHashMap中存儲一些業務規則有序映射條目,我把它發送給客戶端,但我的Ajax響應總是得到由地圖鍵排序。AJAX響應不保留LinkedHashMap的順序從服務器
我的排序功能:
protected Map<Long, String> sortWarehousesMap(Map<Long, String> warehousesMapTemp) {
List<Map.Entry<Long, String>> entries = new ArrayList<Map.Entry<Long, String>>(warehousesMapTemp.entrySet());
Collections.sort(entries, new Comparator<Map.Entry<Long, String>>() {
public int compare(Map.Entry<Long, String> a, Map.Entry<Long, String> b) {
return a.getValue().compareTo(b.getValue());
}
});
Map<Long, String> sortedWarehousesMapTemp = new LinkedHashMap<Long, String>();
for (Map.Entry<Long, String> entry : entries) {
sortedWarehousesMapTemp.put(entry.getKey(), entry.getValue());
}
return sortedWarehousesMapTemp;
}
請幫我我在做什麼錯。
你使用的'LinkedHashMap'在哪裏???,也是'allowedWhses'使用'Long作爲一個鍵即ID'和'String作爲一個值,即Name' – 2014-11-25 05:59:15
我添加了鏈接hashmap返回的函數 – user2375298 2014-11-25 06:03:26