mybatis 常用標簽


 

2、動態sql

 

2.1、if 標簽 :

2.11、動態拼接sql語句;

<if test="name != null and !&quot;&quot;.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、子表關聯主表;

 

 

 

 

 

 

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM