赞
踩
返回的restful接口数据样式:
{
party: [
{
"finishTime": "20191105",
"busiCnt": 1000
}
]
}
1、定义WzwScreenEntity 实体
public class WzwScreenEntity { private String finishTime; private String busiCnt; private String party; public String getFinishTime() { return finishTime; } public void setFinishTime(String finishTime) { this.finishTime = finishTime; } public String getBusiCnt() { return busiCnt; } public void setBusiCnt(String busiCnt) { this.busiCnt = busiCnt; } public String getParty() { return party; } public void setParty(String party) { this.party = party; } }
2、定义list实体
public class WzwScreenChildEntity { public String getFinishTime() { return finishTime; } public void setFinishTime(String finishTime) { this.finishTime = finishTime; } public String getBusiCnt() { return busiCnt; } public void setBusiCnt(String busiCnt) { this.busiCnt = busiCnt; } private String finishTime; private String busiCnt; }
3、具体实现
List<WzwScreenEntity> scList = new ArrayList<>(); scList = mapper.queryData();//从数据库获取数据 Map<String, List> map = new HashMap<>();//定义返回的map if (scList.size() != 0) { for (WzwScreenEntity entity : scList) { WzwScreenChildEntity childEntity = new WzwScreenChildEntity(); childEntity.setFinishTime(entity.getFinishTime()); childEntity.setBusiCnt(entity.getBusiCnt()); List<WzwScreenChildEntity> list = new ArrayList<>(); list.add(childEntity); //当map中的key相同的,防止value值被覆盖。 if (map.containsKey(entity.getParty())) { list.addAll(map.get(entity.getParty())); map.put(entity.getParty(), list); } else { map.put(entity.getParty(), list); } } } LOGGER.info("map================== " + map);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。