当前位置:   article > 正文

JAVA----PageHelper 一般分页_pageinfo pageinfo=new pageinfo(sysmenus)

pageinfo pageinfo=new pageinfo(sysmenus)

pageHelper 一般分页

加入依赖
<!-- pagehelper -->
<dependency>
	<groupId>com.github.pagehelper</groupId>
	<artifactId>pagehelper-spring-boot-starter</artifactId>
	<version>${pagehelper.version}</version>
</dependency>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
配置 springboot
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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
配置Mapper.xml
<select id="selectPage" resultMap="SysUserResultMap">
	select id,username from sys_user
</select>
  • 1
  • 2
  • 3
配置请求数据实体
@Data
public class PageRequest {
    private int pageNum;
    private int pageSize;
}
  • 1
  • 2
  • 3
  • 4
  • 5
封装工具
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;
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
配置返回数据实体
@Data
public class PageResult {
    private int pageNum;
    private int pageSize;
    private long totalSize;
    private int totalPages;
    private List<?> content;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
业务层配置

Mapper

@Repository
public interface SysUserMapper {
    public List<SysUser> list();
}
  • 1
  • 2
  • 3
  • 4

接口

public interface ISysUserService {
    PageResult list(PageRequest pageRequest);
}
  • 1
  • 2
  • 3

实现接口

@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));
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
控制器,装入数据列表测试
@GetMapping("/system/user/list")
@ResponseBody
public Object findPage(PageRequest pageQuery) {
	return userService.list(pageQuery);
}
  • 1
  • 2
  • 3
  • 4
  • 5
接口数据

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/67672
推荐阅读
相关标签
  

闽ICP备14008679号