mybatis

batch update

批量更新
eg:

1
2
3
4
5
6
update table_post p
inner join (
SELECT u.user_id,u.post_count
FROM table_user u
) as c_u on p.user_id = c_u.user_id
set u.post_count=c_u.post_count;

mapper中batch update写法:

1
2
3
4
5
6
7
8
9
<update id="batchUpdate"  parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="" close="" separator=";">
update test
<set>
test=${item.test}+1
</set>
where id = ${item.id}
</foreach>
</update>

TIP:数据库连接必须配置:&allowMultiQueries=true

文档

中文文档
http://www.mybatis.org/mybatis-3/zh/

mybatis-spring
http://www.mybatis.org/spring/zh/

MyBatis Generator
http://www.mybatis.org/generator/
http://generator.sturgeon.mopaas.com/

工具

http://www.mybatis.tk/

# Java, MySQL
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×