分页查询一般分成两次查询一次查总数一次查列表,下面这种写法可以一次返回
sql
<resultMap id="queryOrderListResultMap" type="要返回数据的类型">
</resultMap>
<resultMap type="Long" id="queryOrderListCount" autoMapping="true"/>
<select id="queryOrderList" resultMap="queryOrderListResultMap,queryOrderListCount">
select sql_calc_found_rows
*from 表名
where 1=1
limit ${(req.pageNo - 1) * req.pageSize},#{req.pageSize};
SELECT found_rows() as queryOrderListCount;
</select>
注:resultMap id 不要重复
dao层
List<List<?>> queryOrderList(@Param("req")QueryOrderListReq req)
service
List<List<?>> pageList = OrderMapper.queryOrderList(req);
List<OrderPo> OrderPo= ( List<OrderPo>) pageList.get(0);
QueryOrderListRes res = new QueryOrderListRes().setOrderPo(OrderPo).setTotalCount((Long) pageList.get(1).get(0));