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 ...
随机推荐
- H3C ACL包过滤的局限性
- python的for循环、下标和切片
for循环的格式 for 临时变量 in 列表或者字符串: 循环满足条件时执行的代码 else: 循环不满足条件时执行的代码 例: name = "abcdef&qu ...
- H3C 基于ACL的包过滤技术
- H3C 寻找邻居
- redis_Cacha 爬虫链接redis配置文件
import redisimport json class RedisCache(object): """ 使用redis进行爬虫结果的缓存,并可以进行增量爬取 &quo ...
- visualStudio 无法登陆
如果遇到 visualStudio 无法登陆,可以看下我的方法,可能有用 尝试关闭代理 打开设置.网络.代理,关了它,试试 如果遇到下面的问题: 我们无法刷新此账户的凭据 No home tenant ...
- Roslyn 如何使用 MSBuild Copy 复制文件
本文告诉大家如何在 MSBuild 里使用 Copy 复制文件 需要知道 Rosyln 是 MSBuild 的 dotnet core 版本. 在 MSBuild 里可以使用很多命令,本文告诉大家如何 ...
- P1077 子串乘积正负分类
题目描述 给你一个序列包含 \(n\) 个元素的序列 \(a_1, a_2, \dots , a_n\) (每个元素 \(a_i \ne 0\)). 你需要计算如下两个值: 有多少对数 \((l, r ...
- linux ioctl 接口
大部分驱动需要 -- 除了读写设备的能力 -- 通过设备驱动进行各种硬件控制的能力. 大 部分设备可进行超出简单的数据传输之外的操作; 用户空间必须常常能够请求, 例如, 设 备锁上它的门, 弹出它的 ...
- springboot 动态修改定时任务
1.静态定时 1)启动类加上注解@EnableScheduling @EnableAsync @EnableScheduling @SpringBootApplication @MapperScan( ...