2、动态sql
2.1、if 标签 :
2.11、动态拼接sql语句;
<if test="name != null and !"".equals(name.trim())">
and s.name like CONCAT('%',#{name},'%')
</if>
<if test="courseId != null">
and s.course_id = #{courseId}
</if>
2.2、where 标签:
2.21、当if标签条件都不满足时,去除掉where关键字;
2.22、当多个if标签满足时,去除掉第一个多余的 and 关键字;
2.3、sql 标签:
2.31、定义查询的字段常量;
<sql id="constant">id,name</sql>
<select id="query" >
select <include refid="constant" /> from student
</select>
2.4、set 标签:
2.41、类似于 where 标签,用于update
2.5、trim 标签:
2.51、灵活前后添加去除字段标签;
2.6、choose 标签:
2.61、类似于java中swith功能;
2.7、collection 标签:
2.71、主表关联子表;
2.8、association 标签:
2.81、子表关联主表;