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、子表關聯主表;

