先看效果

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 Basic NAT

  2. Laravel Form-builder使用

    添加formbuilder插件: Composer应用 composer require kris/laravel-form-builder 下载成功 修改配置文件 在config/app.php ‘ ...

  3. js基础——基本包装类型

    1.基本包装类型String   var bz = new String("Li.Linda"); //引用类型(object)         bz.name= bz.subst ...

  4. dotnet core 通过 frp 发布自己的网站

    很多时候写出来的网站只能自己内网访问,本文告诉大家如何通过 Frp 将自己的 asp dotnet core 网站发布到外网,让小伙伴访问自己的网站 通过 frp 的方式,可以解决自己的服务器性能太差 ...

  5. H3CFTP操作示例

  6. 【t092】迷之阶梯

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 在经过地球防卫小队的数学家连续多日的工作之后,外星人发的密码终于得以破解.它告诉我们在地球某一处的古老 ...

  7. vue-learning:0 - 目录

    Vue-learning vue.js学习路径 Vue的API地图 点击查看vue的API地图 视图层 点击可直接到达详情页面 指令 {{ }} / v-html v-if / v-else / v- ...

  8. CentOS yum有时出现“Could not retrieve mirrorlist ”的解决办法——resolv.conf的配置

    国内服务器在运行命令yum -y install wget的时候,出现: Could not retrieve mirrorlist http://mirrorlist.centos.org/?rel ...

  9. codeforces 1194F (组合数学)

    Codeforces 11194F (组合数学) 传送门:https://codeforces.com/contest/1194/problem/F 题意: 你有n个事件,你需要按照1~n的顺序完成这 ...

  10. HBase的安装及使用

    一.摘要以前搜书吧的数据量比较小,使用数据库+静态文件存储的方式就可以搞定,主要有2个系统组成:网站前端+后台服务.事先把图书详情等一些固定内容生成html静态文件和前端的其他静态文件打包部署,动态变 ...