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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章