1.if
<!--使用了别名配置-->
<select id="findByCondition" resultType="user" parameterType="user">
select * from user
<where>
<if test="id!=0">
and id=#{id}
</if>
<if test="username!=null">
and username=#{username}
</if>
<if test="password!=null">
and password=#{password}
</if>
</where>
</select>
2.forEach
collecttion是集合写list 数组写array
open是语句拼接开始 close的语句拼接的结束
item遍历的变量名 separator是分隔符
<select id="findByIdS" parameterType="list" resultType="user">
select * from user
<where>
<foreach collection="list" open="id in(" close=")" item="id" separator=",">
#{id}
</foreach>
</where>
</select>
3.sql语句的抽取
抽取
<!--sql语句的抽取-->
<sql id="selectUser">
select * from user
</sql>
使用
<include refid="selectUser"></include>
<!--sql语句的抽取-->
<sql id="selectUser">
select * from user
</sql>
<!--使用了别名配置-->
<select id="findByCondition" resultType="user" parameterType="user">
<include refid="selectUser"></include>
<where>
<if test="id!=0">
and id=#{id}
</if>
<if test="username!=null">
and username=#{username}
</if>
<if test="password!=null">
and password=#{password}
</if>
</where>
</select>