<!-- 查询物品的id -->
<select id="checkItemsId" parameterType="pd" resultType="java.lang.Integer">
SELECT
i.itemsid
FROM 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">