select a.id as id,
count(distinct b.id) as bid,
count(distinct c.id) as cid
from user a left join user_role b on a.userId = b.userId
left join role c on b.roleId = c.roleId;
要求返回结果形式为:List
String [ ] 中存放的就是三个ID值.
1.到这里,通常我的想法就是,写一个javaBean,javaBean中有这三个属性,分别和这三个值相对应,然后通过resultMap来映射结果集,
如:
count(distinct b.id) as bid,
count(distinct c.id) as cid
from user a left join user_role b on a.userId = b.userId
left join role c on b.roleId = c.roleId;
List
然后再循环迭代list集合转换为String[ ]数组,然后在放入list,最后返回。
2. 实际上是陷入了惯性思维,老是想着用resultMap,其实这里直接用resultClass="hashMap" 可以实现
就不用写javaBean了。
如下:
count(distinct b.id) as bid,
count(distinct c.id) as cid
from user a left join user_role b on a.userId = b.userId
left join role c on b.roleId = c.roleId;
List result= sqlMapClient.queryForList("selectId");
Map hashMap = new HashMap();
for(int i=0;i
String[] areaElement = new String[3];
areaElement[0] = hashMap.get("AID").toString();
areaElement[2] = hashMap.get("BID").toString();
areaElement[3] = hashMap.get("CID").toString();
statResult.add(areaElement);
}
注意:这里的hashMap.get("AID"),键名的来源就是sql语句中的别名。