mybatis if test 相等的情况怎样动态拼接sql

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

posted on 2017-08-03 09:46  blfbuaa  阅读(433)  评论(0编辑  收藏  举报