spring-mvc之Spring中更新多个数据库行-Mybatis
zlslch
阅读:32
2024-02-04 11:18:29
评论:0
我正在尝试更新多个数据库行。使用 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>
给出错误:
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 employee_trips set pickup_drop_time = '01:35:00' where id = 10' at line 3
请您参考如下方法:
附加参数 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)
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。