`
yangyingda2008
  • 浏览: 15164 次
社区版块
存档分类
最新评论

Mybatis使用经验分享之批量操作

阅读更多
Mybatis使用经验分享之批量操作



上次分享了一下Mybatis查询的使用方法,今天再和大家分享先mybatis中的批量操作。
工具/原料

    Mybatis

方法/步骤

    批量删除:

     <delete id= "deleteBatchByXXX" parameterType= "list">

           delete from 表名 where groupon_id in

           <foreach collection="list" item= "item" index ="index"

                open= "(" close =")" separator=",">

                #{item}

           </foreach >

           </delete >

    注意,foreach是循环,用来读取传入的list参数。批量处理是parameterType的类型必须要注意。foreach标签中的collection属性表示传入的是什么集合类型。item表示的是集合中的一个量类似于

    List<String>list;

    for(String str:list){

         ……

    }

    item就相当于str的作用,用来遍历collection。index就是集合的索引。open表示标签以什么开始,close表示标签以什么结束。seprator表示元素之间的间隔。

    批量插入:

     <insert id="insertBatch" >

           insert into 表名 ( uid, groupon_id, create_time, receive_time) values

        <foreach collection="list" item= "item" index ="index" separator=",">

           (#{item.uid,jdbcType=BIGINT}, #{item.grouponId,jdbcType=BIGINT},

          #{item.createTime,jdbcType=INTEGER}, #{item.receiveTime,jdbcType=INTEGER})

        </foreach >

     </insert>

    用法基本同批量删除,这里需要注意item.XXX表示获取该对象的XXX属性。

    批量更新:

    <update id= "updateByIds" parameterType= "map">

        update 表名

        set submit_time = #{submitTime,jdbcType=BIGINT} where uid in

        <foreach collection="list" item= "uid" index ="index"

                open= "(" close =")" separator=",">

                #{ id}

         </foreach >

        </update >

    用法和之前的基本相同,但是需要注意传入的参数是map类型。

         

    批量查询: 
<select id="selecIds" resultType="list" parameterType="java.util.Map">      SELECT
<include refid="Base_Column_List" />
FROM 表名      WHERE id in      
<foreach collection="Ids" item="poiId" index="index" open="(" close=")" separator=",">           
#{Id}       
</foreach>       
  AND pass_uid = #{passUid}       
  <if test="status != null">         
  AND status = #{status,jdbcType=BIGINT}  
  </if>  </select>

    注意标签的用法和上面的大同小异,都是通过传入一个集合对象来进行值得批量查询。
    END

注意事项

    批量操作核心就是一次传入多个数据然后进行相关操作

    增删改查中掌握其中一个其他的也不成问题

camel骆驼男士凉鞋 真皮潮流魔术贴沙滩鞋男鞋 夏季新款正品凉鞋 只要56元!

http://redirect.simba.taobao.com/rd?w=unionnojs&f=http%3A%2F%2Fai.taobao.com%2Fauction%2Fedetail.htm%3Fe%3DYNbrUj%252FZdJwjmraEDZVrLkKA%252ByOYgzU6TbuPAry6zvGLltG5xFicOdXrTUTgh9sMDPIwxrc30rhF03SVjj78hGqYCHH8uv2oZb7Xhy%252F%252BGHmWC8e6JwspUeIZWR1bMnHu%26unid%3D96391090%26ptype%3D100010%26from%3Dbasic&k=5ccfdb950740ca16&c=un&b=alimm_0&p=mm_96391090_7268811_24064425

原博客地址:

java编程之怎样把Long转换成Date的日期格式

http://jingyan.baidu.com/article/19192ad8312e6ae53f57074c.html

java编程之String的日期转换成Long类型的时间

http://jingyan.baidu.com/article/915fc414cdd2eb51384b204c.html

mysql数据库中null值与其他值的比较

http://jingyan.baidu.com/article/9113f81b2adc882b3214c7cb.html

Java编程经验分享之Map使用

http://jingyan.baidu.com/article/215817f7d9d6b31eda1423d8.html

MySql使用经验——通过in查询怎样排序问题

http://jingyan.baidu.com/article/67662997325ccf54d51b84d5.html

Mybatis使用经验之xml注意事项

http://jingyan.baidu.com/article/fec7a1e51d7b451190b4e729.html

Mybatis使用经验分享之批量操作

http://jingyan.baidu.com/article/11c17a2c7f376af446e39d21.html

MyBatis使用经验分享之查询

http://jingyan.baidu.com/article/af9f5a2dd8143b43140a4520.html

linux怎样搭建tomcat服务器

http://jingyan.baidu.com/article/3052f5a1d93c1497f31f860d.html

怎样用linux脚本查询数据中的数据

http://jingyan.baidu.com/article/2c8c281dfb0add0008252a04.html

linux编程实践经验sshpass、md5sum、ssh

http://jingyan.baidu.com/article/cd4c2979ca556c756e6e60aa.html
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics