根据地区进行统计人数,如果没有显示为0

//Controller 层
/**
* @Description
* 根据地区查询所有用户信息
* @author luying
*
*/

@RequestMapping(value = "/toShiCountPage")
@ResponseBody
public ModelAndView toShiCountPage(Integer cid) {
ModelAndView mv = new ModelAndView("admin/tosignup/toShiCountPage");
// 查询到所有地市级的人数统计
Map<String,Object> areaPersonMap = toSignUpService.areaPersonNum(cid);
mv.addObject("cid",cid);
mv.addObject("areaPersonMap",areaPersonMap);
return mv;
}


//service 层

/**
* @Description
*
* 根据地区进行人员数量统计
* @author luying
*
*/
public Map<String,Object> areaPersonNum(Integer cid){
List<ApplyParticipants> areaNum=null;
Map mapArea = new HashMap<>();

mapArea.put("桂林市","0");
mapArea.put("北海市","0");
mapArea.put("梧州市","0");
mapArea.put("贵港市","0");
mapArea.put("玉林市","0");
mapArea.put("河池市","0");
mapArea.put("百色市","0");
mapArea.put("钦州市","0");
mapArea.put("崇左市","0");
mapArea.put("柳州市","0");
mapArea.put("贺州市","0");
mapArea.put("防城港市","0");
mapArea.put("来宾市","0");
try {
areaNum=participantsMapper.countArea(cid);
for(ApplyParticipants applyParticipants:areaNum){
mapArea.put(applyParticipants.getArea(),applyParticipants.getNum());
}

} catch (Exception e) {
e.printStackTrace();
}
return mapArea;
}
原文地址:https://www.cnblogs.com/luYing666/p/11590646.html