mybatis通过foreach 批量插入实体类信息时:
- 在 foreach中最后一个#{} 不要带逗号
<insert id="addUsers">
insert into kunda_user
(userCode,userName,userPassword,gender,birthday,phone,address,userRole) values
<foreach collection="list" item="users" separator=",">
(
#{users.userCode},
#{users.userName},
#{users.userPassword},
#{users.gender},
#{users.birthday},
#{users.phone},
#{users.address},
#{users.userRole}
)
</foreach>
</insert>
否则会报
Error updating database. Cause: java.sql.SQLSyntaxErrorException:
You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near ')
生成的部分sql就为