vue+bootstrap4+mybatis分页
先看效果

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分页的更多相关文章
- Mybatis分页插件
mybatis配置 <!-- mybatis分页插件 --> <bean id="pagehelper" class="com.github.pageh ...
- Mybatis分页和Spring的集成
写了一个Mybatis分页控件,在这记录一下使用方式. 在Maven中加入依赖: ? 1 2 3 4 5 6 7 8 9 <dependencies> ... <depe ...
- mybatis分页插件以及懒加载
1. 延迟加载 延迟加载的意义在于,虽然是关联查询,但不是及时将关联的数据查询出来,而且在需要的时候进行查询. 开启延迟加载: <setting name="lazyLoading ...
- Mybatis分页插件PageHelper的配置和使用方法
Mybatis分页插件PageHelper的配置和使用方法 前言 在web开发过程中涉及到表格时,例如dataTable,就会产生分页的需求,通常我们将分页方式分为两种:前端分页和后端分页. 前端分 ...
- Mybatis分页插件PageHelper使用
一. Mybatis分页插件PageHelper使用 1.不使用插件如何分页: 使用mybatis实现: 1)接口: List<Student> selectStudent(Map< ...
- mybatis分页练手
最近碰到个需求,要做个透明的mybatis分页功能,描述如下:目标:搜索列表的Controller action要和原先保持一样,并且返回的json需要有分页信息,如: @ResponseBody @ ...
- SSM 使用 mybatis 分页插件 pagehepler 实现分页
使用分页插件的原因,简化了sql代码的写法,实现较好的物理分页,比写一段完整的分页sql代码,也能减少了误差性. Mybatis分页插件 demo 项目地址:https://gitee.com/fre ...
- Mybatis分页插件——PageHelper
1.引入依赖 <!-- mybatis分页插件 --> <dependency> <groupId>com.github.pagehelper</groupI ...
- Spring data Jpa 分页从1开始,查询方法兼容 Mybatis,分页参数兼容Jqgrid
废话少说 有参数可以设置 在org.springframework.boot.autoconfigure.data.web.SpringDataWebProperties 中 /** * Whethe ...
随机推荐
- Python--day32--复习:https和http的区别;黏包;黏包问题的解决方式;
1,https和http的区别: https比较安全,传输的时候先对内容进行加密,收到后再进行解密:它的传输内容不容易拦截,就算拦截下来了,也是加密的,看不懂.但是要买证书,一年要好几万,小公司承担不 ...
- 2019-1-29-WPF-设置输入只能英文
title author date CreateTime categories WPF 设置输入只能英文 lindexi 2019-1-29 15:8:4 +0800 2018-2-13 17:23: ...
- H3C 常用的IPv6地址类型及格式
- 2019年7月20日针对iPhone7/7P有锁机的爆破限制
背景 2019年7月20号苹果更改了激活策略,致使卡贴机一夜回到解放前,目前只能使用tmsi或者tmsi+iccid模式激活手机,但是缺点是移动联通信号真的不稳定,漏接电话,无法开启热点等等毛病.尤其 ...
- gulp4.0基本配置,超简单!
最近复习了一下gulp,目前是4.0版本. 下图是基本目录结构,文件里面的内容可以随意添加,超详细简洁啊! 直接上代码(依赖未完全使用): 项目的所有依赖都可以安装,每个都有详细的注释. const ...
- records
2019年数据地址备份: three.js 实例在NextWebProject/static/canvas下边! qlgj 在NextWebProject下边!
- Docker应用容器引擎
1.Docker概述 1.1.Docker简介 Docker 是一个开源的应用容器引擎,基于 Go 语言开发.Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级.可移植的容器中,然后发布到 ...
- Mac-安装Git以及Git的配置
开始使用mac,发现真的不会用.最主要的是不熟悉,使用了才知道,mac默认是带了Git命令的. 原本使用Git生成一对密钥使用,生成的默认文件夹下面去了,与Windows一致,然后就找不到了. 打开命 ...
- 用ubuntu里的vim搭建一个apache2+php+mysql环境一路踩的坑
先是安装apache2,这个很顺利,一个apt install apache就搞定了. (PS:查看linux是否已经安装了apache服务,可以通过执行apachectl -v,如果安装了的话会显示 ...
- Effective TestStand Operator Interfaces
目录 为什么要使用操作员界面? 是什么决定一个好的界面? 用户的类型 和 界面的必要元素 TestStand 架构 TestStand 自带的例子 自定义用户界面 TestStand 提供的三个管理控 ...