问题描述:
分页查询每页20条数据,实际查出来小于20条
解决方案:
既然如此,那我就用group by 让你按主表记录数显示,然后再用mybatis “n+1”的查询方式,再给你填充数据,这样就完美的解决了这个问题。
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.tingsoft.gaea.dto.DepotDto">
<id column="id" property="id" />
<result column="name" property="name" />
<result column="num" property="num" />
<result column="create_time" property="createTime" />
<result column="update_time" property="updateTime" />
<result column="status" property="status" />
<result column="sort" property="sort" />
<collection property="depotType" ofType="com.tingsoft.gaea.pojo.DepotType"
select="findByDepotId" column="{depotId=id}" >
</collection>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
td.id, td.name, td.num, td.create_time, td.update_time, td.status, td.sort
</sql>
<select id="searchPage" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List" />,tdt.id typeId, tdt.name typeName
FROM t_depot td
left join t_depot_type_merge tdtm on td.id = tdtm.depot_id
left join t_depot_type tdt on tdtm.type_id = tdt.id
<where>
and td.status = '1'
<if test="depotName != null and depotName != ''">
and td.name like concat('%', #{depotName}, '%')
</if>
<if test="depotType != null and depotType != ''">
and tdt.name like concat('%', #{depotType}, '%')
</if>
</where>
group by td.id
order by td.sort, td.create_time desc
</select>
<select id="findByDepotId" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/>
from t_depot_type tdt
left join t_depot_type_merge tdtm on tdt.id = tdtm.type_id
where tdtm.depot_id = #{depotId}
</select>