ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

mybatis mapper sql include用法实现sql块复用

2026/8/6 17:25:51 拓冰建站 浏览量
mybatis mapper sql include用法实现sql块复用

一、总SQL

<select id="getxxxMonitorData"resultType="com.xxx.module.system.dal.dataobject.xxx.xxxDO"><include refid="getxxxMonitorDataBaseSql"></include><include refid="whereContent"></include>
</select>

二、Select sql片段

<sql id="getxxxMonitorDataBaseSql">SELECTxxx,xxxFROMxxx T1LEFT JOIN ( xxx ) T2 ON T1.xxx= T2.CODELEFT JOIN xxxt3 ON t3.mn = t1.mnLEFT JOIN xxxt5 ON t5.site_id = t3.idWHERE1 = 1</sql>

二、and sql片段

<sql id="whereContent"><if test="vo.area != null and vo.area != ''">and t3.dl_areacode = #{vo.area}</if>ORDER BY T1.MN ASC,T1.datatime DESC</sql>