您的位置:首页 > 其它

mybatis map foreach遍历

2016-03-20 20:30 405 查看

mybatis map foreach遍历

转至/article/5212354.html

mybatis 遍历map实例

map 数据如下 Map<String,List<Long>>.

测试代码如下:

new HashMap<String, List<Long>>(); List<Long> orgList=new ArrayList<Long>(); orgList.add(10000003840076L); orgList.add(10000003840080L); List<Long> roleList=new ArrayList<Long>(); roleList.add(10000000050086L); roleList.add(10000012180016L); params.put("org", orgList); params.put("role", roleList); List<BpmDefUser> list= bpmDefUserDao.getByMap(params); System.out.println(list.size()); }

dao代码如下:

map){ Map<String,Object> params=new HashMap<String, Object>(); params.put("relationMap", map); return this.getBySqlKey("getByMap", params); }
xml代码如下:

select id="getByMap" resultMap="BpmDefUser"> <foreach collection="relationMap" index="key" item="ent" separator="union"> SELECT * FROM BPM_DEF_USER where RIGHT_TYPE=#{key} and OWNER_ID in <foreach collection="ent" item="id" separator="," open="(" close=")"> #{id} </foreach> </foreach> </select>

index 作为map 的key。item为map的值,这里使用了嵌套循环,嵌套循环使用ent。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: