相比起
多条件查询
(需要注意动态SQL
以及多条件
),这里单条件查询类似于下拉框
,让用户进行选择,实现起来也比较简单。多条件查询(需要注意动态SQL以及多条件)可以参考这里 多条件查询
这里只展示SQL语句编写部分,其余部分参考多条件查询
①三个标签
从外到里面分别是
where、choose、when
②填写进下拉框的响应字段
代码:
<select id="selectBySingle" resultMap="BrandResultMap">
select * from tb_brand
<where>
<choose>
<when test="status != null">
status = #{status}
</when>
</choose>
<choose>
<when test="companyName != null">
company_name = #{companyName}
</when>
</choose>
<choose>
<when test="brandName != null">
brand_name = #{brandName}
</when>
</choose>
</where>
</select>