我正在尝试更新多个数据库行。使用mybatis 3.1
和spring 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行
答案 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)