在使用Mybatis中,有些SQL段经常会使用到,比如select查询的字段等。我们可以将这些字段定义为公共标签,SQL查询引用对应标签即可。
示例如下:
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
ID AS "id", INFO_ID AS "infoId", TITLE AS "title", COVER_IMG AS "coverImg"
</sql>
<select id="customList" resultType="******" parameterType="*******">
select
<include refid="Base_Column_List"/>
from t_public_delivery_info where 1 = 1
</select>
<select id="customMapList" resultType="map" parameterType="******">
select
<include refid="Base_Column_List"/>
from t_public_delivery_info where 1 = 1
</select>
说明:此处直接引用即可,不需要重新书写SQL列