架构师之mybatis-update 带case when 针对多种景况更新

架构师之mybatis-----update 带case when 针对多种情况更新
1.前言.
   如题.
2. 代码.
 
	<update id="batchUpdate" parameterType="java.util.List">
			<foreach collection="list" item="list" index="index" open="begin"
				close=";end;" separator=";">
				update Test
				<set>
					a =(case when (a is null) then #{list.parm1} 
      else a+#{list.parm1} end)
				</set>
				where b= #{list.parm2}
			</foreach>
		</update>



该功能实现如果a为空,则也同样赋值,否则累加. parm1,parm2为list的参数
1 楼 qingming.com 6 分钟前  
不是有IFNULL(expr1,expr2) 或NVL(expr1,expr2)吗?
udpate Test set a=IFNULL(a,0)+#{list.parm1} where b= #{list.parm2}