在Spring中更新多个数据库行 - Mybatis

时间:2016-02-18 11:40:13

标签: spring-mvc mybatis spring-mybatis

我正在尝试更新多个数据库行。使用mybatis 3.1spring 3 这是mapper.xml中的更新查询:

<update id="updateEmployeeTrips" parameterType="com.xxx.xxx.EmployeeTrip">
    <foreach collection="list" item="employeeTrips" index="index" separator=";">
        update employee_trips set pickup_drop_time = #{employeeTrips.pickupTime} where id = #{employeeTrips.id}
    </foreach>
</update>

给出错误:

  

您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在'update employee_trips set pickup_drop_time = '01:35:00'附近使用正确的语法,其中id = 10'在第3行

1 个答案:

答案 0 :(得分:2)

将参数allowMultiQueries=true附加到JDBC的URL,然后尝试:

<强> mapper.xml:

<update id="updateEmployeeTrips" parameterType="java.util.List">
    <foreach collection="list" item="employeeTrips" index="index" separator=";">
        update employee_trips set pickup_drop_time = #{employeeTrips.pickupTime} where id = #{employeeTrips.id}
    </foreach>
</update>

<强> Mapper.java

updateEmployeeTrips(List<employeeTrip> employeeTripList)