先看效果

Springboot+Mybatis+Pagehelper分页具体实现略。

Controller返回数据

@GetMapping("/findByPage")
public AjaxResult findByPage(@RequestParam("pageIndex") Integer pageIndex, @RequestParam("pageSize") Integer pageSize) {
PageInfo<Article> articlePageInfo = articleService.findByPage(pageIndex, pageSize, Sort.DESC.getSort());
return AjaxResult.me().setResultObj(new HashMap<String, Object>(3) {{
put("total", articlePageInfo.getTotal());
put("list", articlePageInfo.getList());
put("pages", articlePageInfo.getPages());
}});
}

js vue

articles里有三个字段:

total(数据不分页总条数,暂时无用,因为没有做具体页数的按钮),

list(当前页数据),

pages(分页总页数)

默认首次打开页面的页号为1,每页数据条数为5

window.onload = function() {
new Vue({
el: '#app',
data: {
articles: '',
page: {
index: 1,
size: 5
}
},
methods: {
pageInfo() {
$.get('/article/findByPage', {'pageIndex': this.page.index, 'pageSize': this.page.size}, (result) => {
// ajax获取数据,result.resultObj={total,list,pages},赋给vue字段articles
this.articles = result.resultObj
})
},
// 上一页,边界由html页面控制
prev() {
this.page.index --;
this.pageInfo()
},
// 下一页,边界由html页面控制
next() {
this.page.index ++;
this.pageInfo()
}
},
created: function () {
// 页面创建后默认分页
this.pageInfo()
}
})
}

html,按钮控制,解决边界问题

通过vue的条件控制来保证分页不越界,pageIndex == 1 时禁用prev按钮,pageIndex == articles.pages(总页数)时禁用next按钮

<div class="btn-group">
<!--prev-->
<button v-if="page.index == 1" type="button" class="btn btn-outline-success" disabled><i class="fa fa-chevron-left" aria-hidden="true"></i></button>
<button v-if="page.index > 1" id="prev" type="button" class="btn btn-outline-success"><i class="fa fa-chevron-left" aria-hidden="true" @click="prev()"></i></button>
<!--pageIndex/pages-->
<button type="button" class="btn btn-outline-success">{{page.index}}/{{articles.pages}}</button>
<!--next-->
<button v-if="page.index == articles.pages" type="button" class="btn btn-outline-success" disabled><i class="fa fa-chevron-right" aria-hidden="true"></i></button>
<button v-if="page.index < articles.pages" id="next" type="button" class="btn btn-outline-success"><i class="fa fa-chevron-right" aria-hidden="true" @click="next()"></i></button>
</div>

vue+bootstrap4+mybatis分页的更多相关文章

  1. Mybatis分页插件

    mybatis配置 <!-- mybatis分页插件 --> <bean id="pagehelper" class="com.github.pageh ...

  2. Mybatis分页和Spring的集成

    写了一个Mybatis分页控件,在这记录一下使用方式. 在Maven中加入依赖: ? 1 2 3 4 5 6 7 8 9 <dependencies>   ...     <depe ...

  3. mybatis分页插件以及懒加载

    1.   延迟加载 延迟加载的意义在于,虽然是关联查询,但不是及时将关联的数据查询出来,而且在需要的时候进行查询. 开启延迟加载: <setting name="lazyLoading ...

  4. Mybatis分页插件PageHelper的配置和使用方法

     Mybatis分页插件PageHelper的配置和使用方法 前言 在web开发过程中涉及到表格时,例如dataTable,就会产生分页的需求,通常我们将分页方式分为两种:前端分页和后端分页. 前端分 ...

  5. Mybatis分页插件PageHelper使用

    一. Mybatis分页插件PageHelper使用  1.不使用插件如何分页: 使用mybatis实现: 1)接口: List<Student> selectStudent(Map< ...

  6. mybatis分页练手

    最近碰到个需求,要做个透明的mybatis分页功能,描述如下:目标:搜索列表的Controller action要和原先保持一样,并且返回的json需要有分页信息,如: @ResponseBody @ ...

  7. SSM 使用 mybatis 分页插件 pagehepler 实现分页

    使用分页插件的原因,简化了sql代码的写法,实现较好的物理分页,比写一段完整的分页sql代码,也能减少了误差性. Mybatis分页插件 demo 项目地址:https://gitee.com/fre ...

  8. Mybatis分页插件——PageHelper

    1.引入依赖 <!-- mybatis分页插件 --> <dependency> <groupId>com.github.pagehelper</groupI ...

  9. Spring data Jpa 分页从1开始,查询方法兼容 Mybatis,分页参数兼容Jqgrid

    废话少说 有参数可以设置 在org.springframework.boot.autoconfigure.data.web.SpringDataWebProperties 中 /** * Whethe ...

随机推荐

  1. Nuget 通过 dotnet 命令行发布

    在开发完成一个好用的轮子就想将这个轮子发布到 nuget 让其他小伙伴可以来使用,但是 nuget.org 的登陆速度太慢,本文介绍一个命令行发布的方法,通过命令行发布的方法可以配合 Jenkins ...

  2. P1011 圆柱体的表面积

    题目描述 输入底面半径 \(r\) 和高 \(h\) ,输出圆柱体的表面积,保留 \(3\) 位小数. 输入格式 输入包含两个实数 \(r,h(1 \le r,h \le 1000)\) 且保证输入的 ...

  3. vue 路由跳转前确认框,刷新浏览器页面前提示确认框

    先看效果图: 1.刷新页面效果: 2.跳转路由(进入别的页面前)效果: 代码: // 路由跳转确认 beforeRouteLeave(to, from, next) { const answer = ...

  4. H3C网络监测工具命令

    1.Debugging 2.Display debugging 3.Display diagnostic-information display diagnostic-information 命令用来 ...

  5. koa2实现简单的验证码

    //首先引入svg-captcha,https://www.npmjs.com/package/svg-captcha const svgCaptcha = require('svg-captcha) ...

  6. vue依赖

    ajax:vue-resource moke数据:body-parser

  7. Popup a window before the MainWindow

    protected override void OnStartup(StartupEventArgs e) { Window w = new Window(); w.ShowDialog(); bas ...

  8. Java实现简单的学生成绩管理系统

    ScoreInformation.java import java.util.Scanner; class ScoreInformation {    private String stunumber ...

  9. Visio图像应用

    图像插入: 直接搜索然后插入 CAD是工程绘图. CAD属性设置框 下面是图像编辑: 通过格式中的旋转进行调整 但是CAD格式的图没有格式 图片可以设置题注 图片层次的使用 CAD图片颜色的修改在 图 ...

  10. 周志华《机器学习》高清电子书pdf分享

    周志华<机器学习>高清电子书pdf下载地址 下载地址1:https://545c.com/file/20525574-415455837 下载地址2: https://pan.baidu. ...