<sql id="queryCondition">
<if test="state!=null">
and d.STATE=#{state}
</if>
<if test="incidentDate!=null and incidentDate!='' ">
and d.INCIDENT_DATE=#{incidentDate}
</if>
<if test="eventsInvolvingTask!=null and eventsInvolvingTask!='' ">
and d.EVENTS_INVOLVING_TASK like CONCAT(CONCAT( '%',#{eventsInvolvingTask}),'%')
</if>
</sql>
c.在需要使用该查询条件的位置使用<include refid="queryCondition"/>来进行引用
d.在查询语句中的做法是:
<select id="queryRefuseLike" parameterType="com.test.dto"
resultType="com.test.dto">
SELECT * FROM EMPLOYEE d
<where>
<include refid="queryCondition"/>
</where>
<choose>
<when test="sortFieldName !='' and sortFieldName !=null and sortType !='' and sortType !=null">
ORDER BY ${sortFieldName} ${sortType}
</when>
<otherwise>ORDER BY d.CREATE_TIME DESC</otherwise>
</choose>
</select>
这样就可以所有的该对象的查询都使用这一个,包括排序!!!