[英]How to insert Arraylist in MyBatis?
Hello today I have problem with insert Arraylist using Mybatis like code bellow: 您好,今天我在使用Mybatis插入Arraylist时遇到了问题,例如以下代码:
@Insert("<script>"
+ " <foreach collection='USER_LIST' item='User' separator=';'> "
+ " insert into tbl_user(username,role) values(#{User.username},#{User.role})"
+ " </foreach>"
+ "</script>")
When I insert single item of arraylist , it worked. 当我插入arraylist的单个项目时,它起作用了。 but If i have multiple item in arraylist error occured: 但是如果我在arraylist中有多个项目发生错误:
insert into tbl_user(username,role) values(?,?); ; values(?,?);
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 '; values('BEAN','BMd')' at line 1
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 '; values('BEAN','BMd')' at line 1; bad SQL grammar []; nested exception is
从异常中,“错误的SQL语法[];嵌套的异常是”,我在您的代码“ separator =';'>”中发现了这一点,没错,myBatis不允许您编写“;”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.