更新(删除)
第一种
SQL中
<update id="remvoeArrays" parameterType="java.util.Arrays">
UPDATE student AS s SET s.delete_sign = 0
WHERE s.no IN (
<foreach collection="nos" index="index" item="item" open="" separator="," close="">
#{item}
</foreach>
)
</update>
DAO 和 Service
public Boolean remvoeArrays(@Param("nos")String[] nos);
第二种
<update id="updateList" parameterType="java.util.List">
UPDATE student AS s SET s.delete_sign = 0
where s.id in (
<foreach collection="list" item="item" index="index" open="" close="" separator=",">
#{item.id}
</foreach>
)
</update>
第三种
注意 需要在数据库添加 &allowMultiQueries=true
jdbc:mysql://192.168.1.109:3306/xxx?&allowMultiQueries=true
<update id="updateList" parameterType="java.util.List">
<foreach collection="list" item="item" index="index">
UPDATE student AS s set s.delete_sign=#{item.delete_sign}
where 1=1 and s.id =#{item.id};
</foreach>
</update>
增加
<insert id="eachAdd" parameterType="pojo.Student">
<foreach collection="list" item="item" separator=";">
I into student (name,sex,age) values (#{item.name},#{item.sex},#{item.age})
</foreach>
</insert>
扩展文章:扩展文章