mybatis 批量更新多个对象,传入参数为List<Object>
展开全部
mybatis支持foreach语句,
语法大致如下:
<update id="batchUpdate">
update tblsupertitleresult
<trim prefix="set" suffixOverrides=",">
<trim prefix="checkState =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.checkState!=null">
when (userHhCode=#{i.userHhCode} and titleId=#{i.titleId}) then #{i.checkState}
</if>
</foreach>
</trim>
<trim prefix=" correctDate =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.correctDate!=null">
when (userHhCode=#{i.userHhCode} and titleId=#{i.titleId}) then #{i.correctDate}
</if>
</foreach>
</trim>
<trim prefix="result =case" suffix="end," >
<foreach collection="list"item="i" index="index">
<if test="i.result!=null">
when (userHhCode=#{i.userHhCode} and titleId=#{i.titleId}) then #{i.result}
</if>
</foreach>
</trim>
</trim>
where
<foreach collection="list" separator="or"item="i" index="index" >
(userHhCode =#{i.userHhCode} andtitleId=#{i.titleId})
</foreach>
</update>
语法大致如下:
<update id="batchUpdate">
update tblsupertitleresult
<trim prefix="set" suffixOverrides=",">
<trim prefix="checkState =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.checkState!=null">
when (userHhCode=#{i.userHhCode} and titleId=#{i.titleId}) then #{i.checkState}
</if>
</foreach>
</trim>
<trim prefix=" correctDate =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.correctDate!=null">
when (userHhCode=#{i.userHhCode} and titleId=#{i.titleId}) then #{i.correctDate}
</if>
</foreach>
</trim>
<trim prefix="result =case" suffix="end," >
<foreach collection="list"item="i" index="index">
<if test="i.result!=null">
when (userHhCode=#{i.userHhCode} and titleId=#{i.titleId}) then #{i.result}
</if>
</foreach>
</trim>
</trim>
where
<foreach collection="list" separator="or"item="i" index="index" >
(userHhCode =#{i.userHhCode} andtitleId=#{i.titleId})
</foreach>
</update>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询