代码中的查询条件是一样的可以提取出来
<select id="getRowCount"
resultType="int">
select count(*)
from sys_logs
<where>
<if test="username!=null and username!=''">
where username like concat("%",#{username},"%")
</if>
</where>
</select>
<select id="findPageObjects"
resultType="com.cy.pj.sys.entity.SysLog">
select *
from sys_logs
<where>
<if test="username!=null and username!=''">
where username like concat("%",#{username},"%")
</if>
</where>
order by createdTime desc
limit #{start Index},#{pageSize}
</select>
修改后:
<select id="getRowCount"
resultType="int">
select count(*)
from sys_logs
<include refid="queryWhereId"/>
</select>
<select id="findPageObjects"
resultType="com.cy.pj.sys.entity.SysLog">
select *
from sys_logs
<include refid="queryWhereId"/>
order by createdTime desc
limit #{start Index},#{pageSize}
</select>
<sql id="queryWhereId">
<where>
<if test="username!=null and username!=''">
where username like concat("%",#{username},"%")
</if>
</where>
</sql>