您的位置:首页 > 数据库

mybatis if test 相等的情况如何动态拼接sql

2015-08-16 18:29 197 查看
今天程序需要根据前台的传过来的状态判断在数据库里是取 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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: