先看效果

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. H3C RIPv2配置举例

  2. python基础七之集合

    集合:可变的数据类型,他里面的元素必须是不可变的数据类型,无序,不重复. 增加 set1 = {'zxc', 'zxf'} set1.add('zxv') # 无序添加 set1.update('zx ...

  3. 用一篇文章了解ppi,dpr,物理像素,逻辑像素,以及二倍图

    这篇文章能让你了解到什么是分辨率.dpr.dip.ppi (dpi相当于ppi,dpi用点表示物理像素密度,ppi是逻辑像素密度) 首先从最简单的ppi开始: 一部手机,有大有小,怎么知道手机的大小用 ...

  4. P1023 活动安排

    题目描述 某个人可以在n个活动中选择一些出来参加.每个活动都有起止时间.而且每个时间段只能参加一个活动.问,这个人最多能加参加几个活动. 可以在活动结束时,立即开始新的活动. 输入格式 第一行是一个整 ...

  5. navicat for mysql (10038)如何解决

    1.授权(youpassword修改为你的密码) #本机登陆mysql: $:mysql -u root -p #改变数据库: mysql>use mysql; #从所有主机: mysql> ...

  6. linux 一个使用整页的 scull: scullp

    为了真实地测试页分配, 我们已随其他例子代码发布了 scullp 模块. 它是一个简化的 scull, 就像前面介绍过的 scullc. scullp 分配的内存量子是整页或者页集合: scullp_ ...

  7. vue-learning:20 - js - 区别:filters / data / computed / watch / methods

    区别:filters / data / computed / watch / methods 在配置对象options中,filters/data/computed/watch/methods的每一项 ...

  8. win7下Oracle库imp导入dmp

    第一步:创建备份文件存储目录 create or replace directory back_file as 'F:\APP\ADMINISTRATOR\ORADATA\ORCL'; create ...

  9. Centos 7.5安装 Redis 5.0.0

    1 我的环境  1.1 linux(腾讯云) CentOS Linux release 7.5.1804 (Core)  1.2 Redis Redis 5.0.0 2 下载 官网 官网下载地址 3 ...

  10. [梁山好汉说IT] 熵的概念 & 决策树ID3如何选择子树

    [梁山好汉说IT] 熵的概念 & 决策树ID3如何选择子树 0x00 摘要 记录对概念的理解,用梁山好汉做例子来检验是否理解正确. 0x01 IT概念 1. 事物的信息和信息熵 1.1 事物的 ...