mybatis if test 相等的情況如何動態拼接sql
阿新 • • 發佈:2019-01-03
今天程式需要根據前臺的傳過來的狀態判斷在資料庫裡是取 where a>b
還是 a<b 還是 a=0 的情況 搞了一下午最後試了下 在if 裡面拼接 #{status}=#{status} 一切ok了
詳細程式碼如下
<if test=" status==1"> and inv.security_inventory < inv.actual_inventory and #{status} = #{status} </if> <if test=" status==2"><!-- 缺貨--> and inv.security_inventory > inv.actual_inventory and #{status} = #{status} </if> <if test=" status==3"><!-- 無貨--> and inv.security_inventory = 0 and #{status} = #{status} </if>