其实很简单, 只需要把容器换成 list
然后在循环中 每次循环末尾 或者直接在循环中实例化 hashmap, 这样就不会造成 map 覆盖了.
- @RequestMapping("controller/json/AssetsController/getAssetsInfosysAndType")
- @ResponseBody
- public Msg getAssetsInfosysAndType() {
- List list = new ArrayList();
- List<AssetsInfosys> assetsInfoSysServiceAll = assetsInfoSysService.getAll();
- List<AssetsStructureLowerMenu> lowerMenuServiceAll = assetsStructureLowerMenuService.getAll();
- for (AssetsInfosys ai :
- assetsInfoSysServiceAll) {
- for (AssetsStructureLowerMenu lmsa :
- lowerMenuServiceAll) {
- if (ai.getName().equals(lmsa.getSuperiormenu())) {
- Map map = new HashMap();
- map.put("assetsInfoSys", ai);
- map.put("msgAssetsType", lmsa);
- list.add(map);
- }
- }
- }
- return Msg.success().add("AllMsgAssetsInfosysAndType", list);
- }
来源: http://www.bubuko.com/infodetail-2767961.html