<sql>标签与<include>标签
<sql>与<include>配合使用可以在映射文件中复用代码片段
- sql标签中可以使用${}来接收include标签传来的参数,并且可以使用#{}来接收mapper传来的参数
<sql id="summaryCondition">
<if test="flag == '0'.toString() and startDate != null and startDate != '' and endDate != null and endDate != ''">
AND DATE_FORMAT(${appointTable}.${appointField}, '%Y%m%d') BETWEEN DATE_FORMAT(#{startDate}, '%Y%m%d') AND DATE_FORMAT(#{endDate}, '%Y%m%d')
</if>
</sql>
<include refid="summaryCondition">
<property name="appointTable" value="woai"/>
<property name="appointField" value="dispatchtime"/>
</include>
如此一来sql片段就可以进行传值了,这样就大大提高了sql片段的复用性,通过传入不同的值实现不同的查询语句