where标签、if标签
<select id="selectCondition" resultType="Envs" parameterType="Envs">
SELECT * FROM http_envs
<where>
<if test="id != null">
id = #{id}
</if>
<if test="name != null">
AND name = #{name}
</if>
<if test="desc != null">
AND `desc` = #{desc}
</if>
</where>
</select>
判断数据对象Envs里id、name、desc不为空则动态添加sql语句
foreach标签
<select id="selectByIds" resultType="Envs" parameterType="list">
SELECT * FROM http_envs
<where>
<foreach collection="list" open="id IN (" close=")" item="id" separator=",">
#{id}
</foreach>
</where>
</select>
属性:
- collection:指定参数容器类型,(list-集合,array-数组)
- open:指定开始sql语句
- close:指定结束sql语句
- item:参数变量名
- separator:指定分隔符