赞
踩
以前经常用 1=1 来解决拼接and问题,
- where
- 1 = 1
- <if>and xxx</if>
- <if>and xxx</if>
- ...
现在用<where>标签即可,如下
- select
- POST_CODE,POST_NAME,REMARK
- from POST
- <where>
- AND POST_CODE = #{postCode}
- AND POST_NAME = #{postName}
- AND REMARK = #{remark}
- </where>
<if>标签直接套在条件外面即可
- SELECT
- POST_CODE,POST_NAME,REMARK
- FROM POST
- <where>
- <if test="postCode != null and postCode !=''">
- AND POST_CODE = #{postCode}
- </if>
- <if test="postName != null and postName !=''">
- AND POST_NAME= #{postName}
- </if>
- <if test="remark != null and remark!=''">
- AND REMARK = #{remark}
- </if>
- </where>
官方文档
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。