zoukankan      html  css  js  c++  java
  • MyBatis map foreach

    以下资料来源于网络,仅供参考学习。
     
    mybatis 遍历map实例
    map 数据如下 Map<String,List<Long>>.
     
    测试代码如下:
     1 public void getByMap() {
     2         Map<String,List<Long>> params=new HashMap<String, List<Long>>();
     3         List<Long> orgList=new ArrayList<Long>();
     4         orgList.add(10000003840076L);
     5         orgList.add(10000003840080L);
     6        
     7         List<Long> roleList=new ArrayList<Long>();
     8        
     9         roleList.add(10000000050086L);
    10         roleList.add(10000012180016L);
    11        
    12         params.put("org", orgList);
    13         params.put("role", roleList);
    14        
    15         List<BpmDefUser> list= bpmDefUserDao.getByMap(params);
    16         System.out.println(list.size());
    17        
    18 }
    dao代码如下:
    1 public List<BpmDefUser> getByMap(Map<String,List<Long>> map) {
    2         Map<String,Object> params=new HashMap<String, Object>();
    3         params.put("relationMap", map);
    4         return this.getBySqlKey("getByMap", params);
    5        
    6 }
    xml代码如下:
     
     1 <select id="getByMap" resultMap="BpmDefUser">
     2        
     3             <foreach collection="relationMap" index="key"  item="ent" separator="union">
     4                 SELECT *
     5                 FROM BPM_DEF_USER
     6                 WHERE RIGHT_TYPE=#{key}
     7                 AND OWNER_ID in 
     8                 <foreach collection="ent"  item="id" separator="," open="(" close=")">
     9                     #{id}
    10                 </foreach>
    11             </foreach>
    12        
    13 </select>
     
    index 作为map 的key。item为map的值,这里使用了嵌套循环,嵌套循环使用ent。
     
     
  • 相关阅读:
    系统相关的信息模块: import sys
    Mysql 解决emoji表情处理问题
    Servlet 个人理解
    Java BufferImage 获取像素矩阵 或 数组
    SVN 出现 R6034 错误 Python导致异常
    Mycat 入门
    Mycat 入门
    Nginx 架构
    Nginx 架构 性能优化
    Nginx 架构 性能优化
  • 原文地址:https://www.cnblogs.com/huangzejun/p/8143950.html
Copyright © 2011-2022 走看看