在mybatis中有时候存在有多少个查询都用到一段公共的sql,不想写几次,就可以用这个include 这个关键字
<!-- 公共代码块 -->
<sql id="Base_Column_List">
id,name
</sql>
在想用到的查询里面引用他。
<select id="getListDevice" resultType="io.farina.modules.device.dto.DeviceDTO">
SELECT <include refid="Base_Column_List" /> FROM tb_device
WHERE dept_id IN (select id from sys_dept where province_id=#{provinceId})
</select>
他的效果和下面这个sql是一样的。
<select id="getListDevice" resultType="io.farina.modules.device.dto.DeviceDTO">
SELECT id,name FROM tb_device
WHERE dept_id IN (select id from sys_dept where province_id=#{provinceId})
</select>