赞
踩
<!-- pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${pagehelper.version}</version>
</dependency>
mybatis:
type-aliases-package: com.xxxxxxx # 搜索指定包别名
mapper-locations: classpath:mapper/**/*Mapper.xml # 配置mapper的扫描
configuration:
map-underscore-to-camel-case: true
pagehelper:
reasonable: true
support-methods-arguments: true
params: count=countSql
helper-dialect: mysql
<select id="selectPage" resultMap="SysUserResultMap">
select id,username from sys_user
</select>
@Data
public class PageRequest {
private int pageNum;
private int pageSize;
}
public class PageUtil {
public static PageResult getPageResult(PageRequest pageRequest, PageInfo<?> pageInfo) {
PageResult pageResult = new PageResult();
pageResult.setPageNum(pageInfo.getPageNum());
pageResult.setPageSize(pageInfo.getPageSize());
pageResult.setTotalSize(pageInfo.getTotal());
pageResult.setTotalPages(pageInfo.getPages());
pageResult.setContent(pageInfo.getList());
return pageResult;
}
}
@Data
public class PageResult {
private int pageNum;
private int pageSize;
private long totalSize;
private int totalPages;
private List<?> content;
}
Mapper
@Repository
public interface SysUserMapper {
public List<SysUser> list();
}
接口
public interface ISysUserService {
PageResult list(PageRequest pageRequest);
}
实现接口
@Service public class SysUserServiceImpl implements ISysUserService { @Autowired private SysUserMapper userMapper; private PageInfo<SysUser> getPageInfo(PageRequest pageRequest) { int pageNum = pageRequest.getPageNum(); int pageSize = pageRequest.getPageSize(); PageHelper.startPage(pageNum, pageSize); List<SysUser> sysMenus = userMapper.selectPage(); return new PageInfo<SysUser>(sysMenus); } @Override public PageResult list(PageRequest pageRequest) { return PageUtil.getPageResult(pageRequest, getPageInfo(pageRequest)); } }
@GetMapping("/system/user/list")
@ResponseBody
public Object findPage(PageRequest pageQuery) {
return userService.list(pageQuery);
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。