spring boot+mybatis连接oracle实现分页功能

使用的是PageHelp插件

1.添加依赖

        
         
            com.github.pagehelper
            pagehelper-spring-boot-starter
            1.2.3
        

2.controller层


	@RequestMapping("getLocationList")
	public Map getLocationList(Integer pageNum, Integer pageSize){
		 Map jsonMap = bannerService.getLocationList(pageNum, pageSize);
		 return jsonMap;
	}

3.service层

     // 查询banner位置列表
	public Map getLocationList(Integer pageNum, Integer pageSize) {
		//PageHelper分页插件使用
		PageHelper.startPage(pageNum, pageSize);
		List bannerLocationList = bannerLocationDao.selectAll();
		//将数据库查出的值扔到PageInfo里实现分页效果
		PageInfo pageInfo = new PageInfo<>(bannerLocationList);
		//将结果展示到map里
		Map jsonMap = new HashMap();
		jsonMap.put("ret", "0");
		jsonMap.put("msg", "SUCCESS");
		jsonMap.put("body", bannerLocationList);//数据结果
		jsonMap.put("total", pageInfo.getTotal());//获取数据总数
		jsonMap.put("pageSize", pageInfo.getPageSize());//获取长度
		jsonMap.put("pageNum", pageInfo.getPageNum());//获取当前页数
		return jsonMap;
	}

4.dao层

List selectAll();

5.mapper层

6.返回结果:

访问:https://localhost:8080/项目名/banner/getLocationList?pageNum=1&pageSize=2

{
    "ret": "0",
    "msg": "SUCCESS",
    "total": 4,
    "pageSize": 2,
    "body": [
        {
            "id": 1,
            "status": 1,
            "moduleAttrId": 1,
            "locationAttrId": 2,
            "name": "闪屏",
            "lxxz": "GIF,JPG,PNG,JPEG",
            "dxxz": 2,
            "ccxz": "540,960",
            "chanelId": "00000"
        },
        {
            "id": 2,
            "status": 1,
            "moduleAttrId": 3,
            "locationAttrId": 4,
            "name": "首页轮播图",
            "lxxz": "GIF,JPG,PNG,JPEG",
            "dxxz": 2,
            "ccxz": "750,320",
            "chanelId": "00000"
        }
    ],
    "pageNum": 1
}

 

你可能感兴趣的:(java)