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>标签

发布了68 篇原创文章 · 获赞 36 · 访问量 2万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章