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。
     
     
  • 相关阅读:
    DeflateStream类
    BufferedStream类
    FileStream类
    Asp.net MVC Comet 推送
    MVC 读书笔记
    MVC部署
    MVC系统过滤器、自定义过滤器
    MVC 路由规则
    MVC 模型绑定
    边双+点双模板
  • 原文地址:https://www.cnblogs.com/huangzejun/p/8143950.html
Copyright © 2011-2022 走看看