When we do a batch update, we can know that we often use mybatis dynamic SQL to stitch multiple SQL statements, such as:
<UpdateID= "Alterstudentdormbatch"ParameterType= "Map"> <foreachCollection= "Studormmap"Index= "Stuid"Item= "Newdorm"Separator=";">UPDATE Student<Set>Stu_dorm=#{newdorm}</Set>WHERE Stu_id=#{stuid}</foreach> </Update>
However, has been an error, the SQL statement obviously no problem, when debugging found that the first map to the database is not a problem, and the subsequent map is not passed in, suspect that the database only accepted the first update SQL statement.
Later found that the original MySQL batch update is to our initiative to set up, that is, in the database connection URL set up, plus * &allowmultiqueries=true * , you can send multiple SQL statements (batch) at once.
The above is the problem of batch update, in fact, can be re-optimized, through the case...when...then. To stitch a SQL send.
MyBatis a map to send multiple SQL problems encountered