日期:2014-05-16  浏览次数:20383 次

如何按照城市首字母给城市分类,并加上热门城市
如何按照城市首字母给城市分类,并加上热门城市

------解决方案--------------------
@RequestMapping("getcity")
public String example(Model model, HttpServletRequest request, HttpServletResponse response) {

// 查询热门
List<Map<String, Object>> list = queryGetCityService.getHotCitys();
model.addAttribute("CityList", list);

// 按首字母查排序所有城市
List<Map<String, Object>> allCityList = queryGetCityService.getAllcityByLetter();

Map<String, List<Object>> mapZm = new LinkedHashMap<String, List<Object>>();
String[] zm = new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M",
"N", "P", "Q", "R", "S", "T", "W", "X", "Y", "Z" };

for (int i = 0; i < zm.length; i++) {
mapZm.put(zm[i], new ArrayList<Object>());
}
//将对应的list放入相应的字母
for (Map<String, Object> map : allCityList) {
//暂时存放首字母
String pinyin = ((String) map.get("PINYIN")).substring(0, 1).toUpperCase();
//如果mapZm的key 包含pinyin
if (mapZm.containsKey(pinyin)) {
mapZm.get(pinyin).add(map);
}
}

model.addAttribute("mapZm", mapZm);

return "groupbuy/allcityList.ftl";

}

------解决方案--------------------
数据库里三个字段,一个存拼音一个存汉字一个存热门,拼音用作排序,热门用来判断是不是热门城市然后显示成特殊的样式。