mapper中注解开发使用if需要注意的问题

@Update("<script>"
			+ "update product set pname=#{pname},market_price=#{market_price},shop_price=#{shop_price}"
			+ "<if test='pimage != null'>,pimage=#{pimage}</if>"
			+ ",pdate=#{pdate},is_hot=#{is_hot},pdesc=#{pdesc},cid=#{category.cid} where pid=#{pid}"
			+ "</script>")

test中取值不需要#号,直接写属性名

如果test中出现字符串,不能使用单引号,使用双引号转义

如果出现大于号小于号 ,转义使用

不要忘记加<script>标签

发布了66 篇原创文章 · 获赞 35 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_41890624/article/details/103476428