mybatis的sql拼接
<insert id="addlist">
insert into user(user_name,password)
values
<foreach item="item" index="index" collection="userList" separator=",">
(#{item.userName},SYSDATE())
</foreach>
</insert>
java controller的代码
List<User> userList = new ArrayList<User>();
for (int i = 1; i <= num; i++) {
User user = new User();
user.setUserName("a" + i);
user.setPassword("b"+i);
userList.add(user);
}
userDao.addlist(userList);