mybatis map foreach遍历


mybatis map foreach遍历


mybatis 遍历map实例

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



测试代码如下:


复制代码
public void getByMap(){
        Map<String,List<Long>> params=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代码如下:

public List<BpmDefUser> getByMap(Map<String,List<Long>> 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值