首页 > 解决方案 > 在 iBatis 中使用多个更新语句时出错

问题描述

我正在<foreach>标签下执行多个更新语句。在 MySQL 工作台中执行时,查询似乎工作正常。但是在通过springboot应用程序运行时,我面临如下错误:

更新.xml

<update id="saveSeats" parameterType="map" useGeneratedKeys="true">
        <foreach collection="seats" item="seat" separator=";">
            UPDATE t002_seat_mst SET IS_ASSIGNED=#{seat.isAssigned},TEAM_ID=#{seat.team.teamId} WHERE (SEAT_ID=#{seat.seatId} AND MAP_ID=#{mapId})
        </foreach>;
    </update>

错误日志

### 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 'UPDATE t002_seat_mst SET IS_ASSIGNED=1,TEAM_ID=31 WHERE (SEAT_ID=677 AND MAP_ID=' at line 1
### The error may exist in config/SeatsMapper.xml
### The error may involve com.seat.arrangement.dao.mapper.MapMapper.saveSeats-Inline
### The error occurred while setting parameters
### SQL: UPDATE t002_seat_mst SET IS_ASSIGNED=?,TEAM_ID=? WHERE (SEAT_ID=? AND MAP_ID=?) ; UPDATE t002_seat_mst SET IS_ASSIGNED=?,TEAM_ID=? WHERE (SEAT_ID=? AND MAP_ID=?) ; UPDATE t002_seat_mst SET IS_ASSIGNED=?,TEAM_ID=? WHERE (SEAT_ID=? AND MAP_ID=?) ;
### 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 'UPDATE t002_seat_mst SET IS_ASSIGNED=1,TEAM_ID=31 WHERE (SEAT_ID=677 AND MAP_ID=' at line 1
; bad SQL grammar []; nested exception is 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 'UPDATE t002_seat_mst SET IS_ASSIGNED=1,TEAM_ID=31 WHERE (SEAT_ID=677 AND MAP_ID=' at line 1] with root 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 'UPDATE t002_seat_mst SET IS_ASSIGNED=1,TEAM_ID=31 WHERE (SEAT_ID=677 AND MAP_ID=' at line 1

标签: mysqlxmlspring-bootmybatisibatis

解决方案


推荐阅读