2017-05-19 15 views
0

こんにちは、今日私は、インサートのArrayListが怒鳴るようなコードを使用してMyBatisのに問題があります。MyBatisにArraylistを挿入するには?

@Insert("<script>" 
      + " <foreach collection='USER_LIST' item='User' separator=';'> " 
      + "  insert into tbl_user(username,role) values(#{User.username},#{User.role})" 
      + " </foreach>" 
      + "</script>") 

私はArrayListの単一の項目を挿入し、それが働きました。私は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 
+0

この[回答](http://stackoverflow.com/questions/17563463/mybatis-insert-list-values)が役立ちます。 –

+0

大丈夫、今すぐご利用いただきました –

+0

**このリンクをご覧ください:** [MyBatis Insert List values](https://stackoverflow.com/questions/17563463/mybatis-insert-list-values/45693515#45693515 ) –

答えて

0

を例外から、「悪いSQL文法[];ネストされた例外がある」、 と私はあなたのコードでこれを見つけ、「区切り= 『;』>」それは正しいです、私のバトスはあなたに ';'

+0

大丈夫、私はそれを得た。ありがとうございました –

関連する問題