mybatis 分页工具 pagehelper


        <dependency>
            <groupId>com.github.pagehelpergroupId>
            <artifactId>pagehelper-spring-boot-starterartifactId>
            <version>1.2.10version>
        dependency>

 @RequestMapping("/getNewsLimit")
    public BaseResult<?> getNewsLimit(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);//这行是重点,表示从pageNum页开始,每页pageSize条数据
        List<TbNews> list = tbNewsMapper.findAll();
        PageInfo<TbNews> tbNewsPageInfo = new PageInfo<TbNews>(list);
        BaseResult<JSONObject> result = BaseResult.result(JSONObject.class);
        JSONObject returnJson = new JSONObject();
        returnJson.put("total", tbNewsPageInfo.getTotal());
        returnJson.put("newsList", tbNewsPageInfo.getList());
        result.setData(returnJson);
        return result;
    }

你可能感兴趣的:(Spring,Boot,java后台)