<foreach>标签
传统写法,参数只能写死,不灵活
<select id="findByIds" parameterType="list" resultType="user">
select * from user where id in(1,2,3)
</select>
使用<foreach>标签
<select id="findByIds" parameterType="list" resultType="user">
select * from user
<where>
<foreach collection="list" open="id in(" close=")" separator="," item="id">
#{id}
</foreach>
</where>
</select>
collection表示要遍历的类型,open表示传统写法开头的部分,close表示传统写法结束的部分,separator表示传统写法用的什么分隔符,item表示给要遍历的变量取个名字,必须和下面的#{}里面的一致
sql语句抽取
<!--sql语句抽取-->
<sql id="selectUser">select * from user </sql>
抽取后可通过<include>标签提取插入
<if>标签和sql语句抽取一起使用
<select id="findByCondition" parameterType="user" resultType="user">
/*这里使用sql语句抽取的方式*/
<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>
<plugins>标签
<!--配置分页助手插件-->
<plugins>
<plugin interceptor="com.github.pagehelper.PageHelper">
<property name="dialect" value="mysql"/>
</plugin>
</plugins>