zoukankan      html  css  js  c++  java
  • 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。
  • 相关阅读:
    JSTL之迭代标签库
    java中的IO流
    浅谈代理模式
    TreeSet集合
    网络编程之UDP协议
    Java中的多线程
    Java中的面向对象
    JavaScript 函数表达式
    JavaScript 数据属性和访问器属性
    JavaScript 正则表达式语法
  • 原文地址:https://www.cnblogs.com/yg_zhang/p/4314602.html
Copyright © 2011-2022 走看看