zoukankan      html  css  js  c++  java
  • MyBatis In的使用

    http://blog.csdn.net/unei66/article/details/17792503

     MyBatis In的使用
    标签: mybatisin
    2014-01-03 16:23 7454人阅读 评论(0) 收藏 举报
     分类: Java Web(12)  
    版权声明:本文为博主原创文章,未经博主允许不得转载。
    目录(?)[+]
                 项目中where条件中用到in,我理所当然的拼了个字符串传进去了,郁闷的是程序一直运行正常,测试case一直没有覆盖到这种情况,今天发现了,原来是程序的问题,我以为mybatis有bug呢。。。。。故记下此问题,留作笔记。
               
               1.解决方法(多参数)
                   Map.xml
                  
    [html] view plaincopy在CODE上查看代码片派生到我的代码片
    <select id="getEntityList" resultType="App" parameterType="map">  
        select * from t_app   
        where status=#{status}  
        <if test="flag!=null ">  
            and id not in  
            <foreach item="item" index="index" collection="ids" open="("  
                separator="," close=")">  
                #{item}  
            </foreach>  
        </if>  
    </select>  
              传入的参数为Map<String,Object>
              数据:status:1
                         ids:int[]{101,103,61,75}
     
             2.一个参数           
                a.如果参数的类型是List, 则在使用时,collection属性要必须指定为 list
                               findByIds(List<Long> ids)
                             
    [html] view plaincopy在CODE上查看代码片派生到我的代码片
    <select id="findByIdsMap" resultMap="BaseResultMap">  
      
             Select  
      
             <include refid="Base_Column_List" />  
      
             from jria where ID in  
                      <foreach item="item" index="index" collection="list"   
                             open="(" separator="," close=")">  
                            #{item}  
                    </foreach>  
      </select>   
    
               b.如果参数的类型是Array,则在使用时,collection属性要必须指定为 array
                         findByIds(Long[] ids)
                       
    [html] view plaincopy在CODE上查看代码片派生到我的代码片
    <select id="findByIdsMap" resultMap="BaseResultMap">  
                    select  
                    <include refid="Base_Column_List" />  
             from jria where ID in  
                     <foreach item="item" index="index" collection="array"   
                            open="(" separator="," close=")">  
                           #{item}  
                   </foreach>  
     </select>   
  • 相关阅读:
    Android开发(30)--AutoCompleteTextView和MultiAutoCompleteTextView自动提示输入内容
    哈希表总结
    Java HttpClient使用小结
    Cocos2d-精灵的几个常识
    java模式之装饰模式
    Spring中AOP的模拟实现
    [置顶] 安卓UI组件之ListView详解
    当开源遇到禅修——“第八届开源世界开源中国高峰论坛”及“2013开源群英会”有感
    [置顶] Adapter详解
    PRJ: Split a nodes-map into some triangles
  • 原文地址:https://www.cnblogs.com/jcz1206/p/5038484.html
Copyright © 2011-2022 走看看