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

来源:互联网 发布:用户画像数据建模 编辑:程序博客网 时间:2024/05/18 03:16

今天程序需要根据前台的传过来的状态判断在数据库里是取 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>

3 0
原创粉丝点击