mybatis 技术总结

本文档内的技术是我自己用过,在这里分享出来。的本文档会持续的更新。

首先分享两个参考过的文章

1、  mybatis    http://blog.csdn.net/kutejava/article/details/9164353#t0

2、  mybatis官网:http://mybatis.github.io/mybatis-3/zh/getting-started.html

maven 引用 开发需要的mybatis的包

<!-- mybatis 整合到spring里面 -->
 <dependency>  
            <groupId>org.mybatis</groupId>  
            <artifactId>mybatis-spring</artifactId>  
            <version>1.2.3</version>  
        </dependency>
        <!-- mybatis 本身的包 -->
        <dependency>  
            <groupId>org.mybatis</groupId>  
            <artifactId>mybatis</artifactId>  
            <version>3.2.7</version>  
        </dependency>
        <dependency><!-- 懒加载使用 -->
    <groupId>cglib</groupId>
    <artifactId>cglib</artifactId>
    <version>2.2</version>
</dependency>
<dependency><!-- 懒加载使用 -->
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.3.1</version>
</dependency>

3、mybatis 批量修改数据

(1)多条数据相同字段修改为相同的值,如多个数据修改 status 位相同值,

  <update id="userStateUpdateBatch" parameterType="java.util.Map">
  update users set status=#{status}
  <where>
      id in
      <foreach collection="userIds" item="id" index="index" open="(" separator="," close=")" >  
          #{id}  
        </foreach>
  </where>
  </update>

(2)多条数据相同字段修改为不同的值,批量修改多条数据

<update id="batchUpdate"  parameterType="java.util.List">      
       <foreach collection="list" item="item" index="index" open="begin" close="end;" separator=";">
                update test 
                <set>
                  test=${item.test}+1
                </set>
                where id = ${item.id}
        </foreach>         
    </update>

你可能感兴趣的:(mybatis)