MyBatis3.X中高效能sql的片段使用
阿新 • • 發佈:2021-02-10
技術標籤:ssm學習筆記mybatisjavasqlmysql
常⽤select * 去查詢資料庫 ⼩項⽬沒問題,
⾼併發項⽬不推薦這樣使⽤,查詢效能低,
應該選擇需要的欄位 什麼是sql⽚段
根據業務需要,⾃定製要查詢的欄位,並可以復⽤
使用sql片段 然後include標籤引用即可
code:
<sql id="base_video_field">
id,title,summary,cover_img
</sql>
<!--
statement sql
id: 當前mapper下需要唯一
resultType : sql查詢結果集的封裝
-->
<!--<select id="selectById" parameterType="java.lang.Integer" resultType="net.xdclass.online_class.domain.Video">-->
<select id="selectById" parameterType="java.lang.Integer" resultType="Video">
select < include refid="base_video_field"/> from video where id = #{video_id,jdbcType=INTEGER}
</select>
<select id="selectListByXML" resultType="Video">
select <include refid="base_video_field"/> from video
</select>