记录下分页实现,便于下次查看使用。
一、普通分页
service接口
代码语言:javascript复制/**
* 分页查询
* @param gasTimedTask
* @return
*/
IPage<GasTimedTask> findByPage(GasTimedTask gasTimedTask);
service实现类
代码语言:javascript复制@Override
public IPage<GasTimedTask> findByPage(GasTimedTask gasTimedTask) {
IPage<GasTimedTask> iPage = new Page<>(gasTimedTask.getCurrentPage(), gasTimedTask.getPageSize());
QueryWrapper<GasTimedTask> qw = new QueryWrapper<GasTimedTask>();
qw.orderByDesc("create_time");
return this.page(iPage, qw);
}
二、一对多分页
service接口
代码语言:javascript复制/**
* 分页查询
* @param houseSpaceAssay
* @return
*/
IPage<HouseSpaceAssay> findByPage(HouseSpaceAssay houseSpaceAssay);
service实现类
代码语言:java复制@Override
public IPage<HouseSpaceAssay> findByPage(HouseSpaceAssay houseSpaceAssay) {
Page<HouseSpaceAssay> page = new Page<>(houseSpaceAssay.getCurrentPage(), houseSpaceAssay.getPageSize(),houseSpaceAssayMapper.selectCount(new QueryWrapper<>()));
List<HouseSpaceAssay> list = houseSpaceAssayMapper.findByPage(new PageAdapter(houseSpaceAssay.getCurrentPage() - 1, houseSpaceAssay.getPageSize()));
page.setRecords(list);
return page;
}
mapper
代码语言:javascript复制/**
* 分页查询
* @param pageAdapter
* @return
*/
List<HouseSpaceAssay> findByPage(@Param("pageAdapter") PageAdapter pageAdapter);
xml
代码语言:javascript复制<select id="findByPage" resultMap="BaseResultMap">
select *
from camera_region
order by seq
limit #{pageAdapter.begin},#{pageAdapter.size}
</select>
完!