在網上搜索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!!!