在网上搜索mybatis批量增加数据的方法,以及主键自动生成的方法,大多数基本都是自增批量插入的,不是用的uuid,我找了半个小时都没找到批量增加uuid的方法,然后就灵光一闪,这样写:
<insert id="createUserList" parameterType="java.util.List" > INSERT into
sys_user( id, username, password, phone, create_date )VALUES <foreach
collection="list" item="item" index="index" separator="," > ( (SELECT
REPLACE(UUID(), '-', '') AS id), #{item.username}, #{item.password},
#{item.phone}, now() ) </foreach> </insert>
把(SELECT REPLACE(UUID(), '-', '') AS id) 引入进来,ok!!!
热门工具 换一换