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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/YiWangJiuShiXingFu/article/details/88419535

使用的是PageHelp插件

1.添加依赖

        <!--PageHelp分页-->
         <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.3</version>
        </dependency>

2.controller层


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

3.service层

     // 查询banner位置列表
	public Map<String, Object> getLocationList(Integer pageNum, Integer pageSize) {
		//PageHelper分页插件使用
		PageHelper.startPage(pageNum, pageSize);
		List<BannerLocationEntity> bannerLocationList = bannerLocationDao.selectAll();
		//将数据库查出的值扔到PageInfo里实现分页效果
		PageInfo<BannerLocationEntity> pageInfo = new PageInfo<>(bannerLocationList);
		//将结果展示到map里
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		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<BannerLocationEntity> selectAll();

5.mapper层

<select id="selectAll" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select ID, STATUS, MODULE_ATTR_ID, LOCATION_ATTR_ID, NAME, LXXZ, DXXZ, CCXZ, CHANEL_ID
    from EDU_BAC_AD_CLIENT_LOCATION
  </select>

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
}

猜你喜欢

转载自blog.csdn.net/YiWangJiuShiXingFu/article/details/88419535