if
<select id="getEmpById" parameterType="emp" resultType="emp">
select * from emp
<where>
<if test="ename!=null and ename!=''">
ename=#{ename}
</if>
<if test="job!=null and job!=''">
and job=#{job}
</if>
</where>
</select>
where
set
<update id="upadatEmp" parameterType="emp">
update emp
<set>
<if test="ename!=null and ename!=''">
ename=#{ename},
</if>
<if test="job!=null and job!=''">
job=#{job}
</if>
<where>
<if test="empno!=null">
empno=#{empno}
</if>
</where>
</set>
</update>
trim
prefix:要增加的前缀
prefixOverrides:要去除的前缀
suffix:要增加的后缀
suffixOverrides:要去除的后缀
<select id="getEmptrim" parameterType="emp" resultType="emp">
select * from emp
<trim prefix="where" prefixOverrides="and | or">
<if test="ename!=null and ename!=''">
and ename=#{ename}
</if>
<if test="job!=null and job!=''">
and job=#{job}
</if>
</trim>
</select>
标签:ename,empno,job,emp,sql,动态,select From: https://www.cnblogs.com/zhangsai/p/17757511.html