SpringBoot整合pagehelper分页插件用法

SpringBoot整合pagehelper分页插件用法

    *用到了JSONObject,PageInfo*。此外,appllication.yml文件无需另外配置。

1.添加pom依赖:

      <!--pagehelper-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.5</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.2</version>
        </dependency>

2.Controller层:

        @PostMapping("/getList")
	public ResponseEntity getContens(@RequestBody JSONObject query){
		PageInfo<ContentManagementEntity>                 
        list=contentManagementService.getList(query);
		return new ResponseEntity(list,HttpStatus.OK);
	}

3.Server层:

        public PageInfo<ContentManagementEntity> getList(JSONObject query){
		Integer pageNum= query.getInteger("pageNum");
		Integer pageSize= query.getInteger("pageSize");
		PageHelper.startPage(pageNum, pageSize);
		List<ContentManagementEntity> list= (List<ContentManagementEntity>)     
        contentManagementMapper.getList(query);
		PageInfo<ContentManagementEntity> pageInfo =new PageInfo<ContentManagementEntity> 
        (list);
		return pageInfo;
	}

4.Mapper层:

List<ContentManagementEntity> getList(JSONObject query);

mapper.xml里的SQI语句就不贴出来了,完~~~

猜你喜欢

转载自blog.csdn.net/ckc_666/article/details/85045467
今日推荐