mybatis 中使用if else 进行判断

来源:互联网 发布:oracle查看数据库名称 编辑:程序博客网 时间:2024/05/20 11:32
<!-- 查询物品的id --><select  id="checkItemsId" parameterType="pd" resultType="java.lang.Integer">SELECTi.itemsidFROM  pq_goods_items  i<where>            <!--方式一使用choose的方式查询-->           <!-- <choose>               <when test="parentId !=0 ">parentTypeId=#{parentId}</when>               <when test="parentId==0">parentTypeId is null</when>            </choose> -->           <!--方式二使用if的方式查询-->            <if test="color!=null">            i.personone=#{personone}AND    i.persontwo=#{persontwo}            AND    i.color=#{color}          </if>            <if test="color==null">            i.personone=#{personone}AND    i.persontwo=#{persontwo}            AND    i.color is null          </if>         </where> </select>


需要注意的是  使用了where标签以后,sql中不在使用where字段来限制条件

如果判断条件有多个 中间用 and 表示并列

<if test="color!=null and personone!=null">  


原创粉丝点击