美文网首页
Springboot整合Pagehelper实现分页(结合vue

Springboot整合Pagehelper实现分页(结合vue

作者: 目光下的暮光 | 来源:发表于2020-05-29 14:15 被阅读0次

1、引入依赖(starter)

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

2、配置yml文件

pagehelper:
  helperDialect: mysql
  reasonable: true 
  supportMethodsArguments: true 
  pageSizeZero: false #pageSize=0 

3、编写controller

 @GetMapping("/all")
    public PageInfo getBookAll(@RequestParam(defaultValue = "1") int pageNum,
                                 @RequestParam(defaultValue = "10") int pageSize, Book book) {
        PageHelper.startPage(pageNum, pageSize);
        PageInfo pageInfo = new PageInfo(bookDao.queryAll(book));
        return pageInfo;
    }

4、前端vue

(1)与后端数据交互

  page(currentPage){
                const _this=this;
                axios.get("http://localhost:8888/book/all?pageNum="+currentPage+"&pageSize=10").then(function (res) {
                    console.log(res.data);
                    _this.tableData=res.data.list;
                    _this.total=res.data.total;
                })
            }

(2)分页代码(Element UI)

 <el-pagination
                background
                layout="prev, pager, next"
                :total="total"
                @current-change="page"
        >
        </el-pagination>

5、效果如下图

image.png

相关文章

网友评论

      本文标题:Springboot整合Pagehelper实现分页(结合vue

      本文链接:https://www.haomeiwen.com/subject/eqbxzhtx.html