springboot+Thymeleaf+layui 实现分页
layui分页插件
引入相关的js和css
layui:css <link rel="stylesheet" th:href="@{layui/css/layui.css}">
layui:js <script th:src="@{layui/layui.js}"></script>
jquery <script th:src="@{js/jquery.min.js}"></script>
th:src="@{xxx}" 这个对应的文件路径 当然采用cdn 直接导入链接也可以直接按照html格式去写
CDN 方式
<!-- 引入 layui.css -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/layui/2.6.5/css/layui.min.css">
<!-- 引入 layui.js -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/layui/2.6.5/layui.min.js">
<!-- 引入 jquery.js -->
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
引入分页插件
<script th:inline="JavaScript">
layui.use('laypage', function () {
var laypage = layui.laypage;
laypage.render({
elem: 'userpage', //任意一个div 的ID,但不用加 # 号 将分页添加到该div下面
count: [[${session.gzcount}]], //数据总数,后台获取
limit: 5, //每页条数
curr: [[${session.pages}]], //当前页数
layout: ['prev', 'page', 'next', 'skip'], //这里就是一些功能按钮 详情可以阅读 layui的官方文档
jump: function (obj, first) {
//这里是首次不执行,以为当我们异步请求后 需要重新加载该页面获取新的数据 如果直接写在外面 会循环调用 导致页面一直重复加载
if (!first) {
$.ajax({
type: "POST",
url: "/user/gzpages", //接口路径
data: {"pages":obj.curr, //obj.curr得到当前页,以便向服务端请求对应页的数据。
"limit":obj.limit,//obj.limit得到每页显示的条数
},
success: function(data) {
location.reload() //重新加载页面 当然这里可以进行判断 如果后台数据没有改动 可以不用重新加载
},
});
}
}
});
});
</script>
Controller
直接上代码了,
@RequestMapping("/user/gomygz")
public String mygz(HttpServletRequest request,Model model){
String gzpages =(String) request.getSession().getAttribute("gzpages");
Map finduserfansmap = userService.finduserfansmap(request, gzpages);
/**这个是一个封装参数的方法可以封装到service中 也可以直接放在controller 当然最好封装到Service中
public Map finduserfansmap(HttpServletRequest request, String pages){
String limit =(String) request.getSession().getAttribute("limit");
String pages=(String) request.getSession().getAttribute("pages");
Map map=new HashMap();
int pages1=1,limit1=5; //初始化参数 (当前页 和每页条数)
if (pages!=null&&limit!=null){ //第一次进入页面 session pages limit 是空的 我们就直接用最初的值 当异步请求创建了session 后我们就用 session的值
pages1 = Integer.valueOf(pages);
limit1 = Integer.valueOf(limit);
}
map.put("start",pages1*limit1-limit1);
map.put("end",pages1*limit1);
return map;
}
**/
List<Fansmsg> relations = userService.findto_userid(finduserfansmap);
request.getSession().setAttribute("mygz",relations);
return "user/mygz";
}
//切换页码的请求
@RequestMapping("/user/gzpages")
@ResponseBody
public int gzpages(String pages,String limit,HttpServletRequest request){
//将参数封装到session里面 每次请求都会更新session的值
request.getSession().setAttribute("pages",pages);
request.getSession().setAttribute("limit",limit);
return 1;
}
Mapper
就是一个简单的SQL语句
<select id="xxx" parameterType="map" resultType="pojo">
select * from table where 查询条件 limit #{start},#{end}
</select>
这样就可以实现了
当然用vue 可以双向绑定 前后端分离 后端只负责提供各种json数据 前端用vue 遍历数据 就比这简单多了
springboot+Thymeleaf+layui 实现分页的更多相关文章
- Springboot+Thymeleaf+layui框架的配置与使用
前言Springboot默认是不支持JSP的,默认使用thymeleaf模板引擎.所以这里介绍一下Springboot使用Thymeleaf的实例以及遇到的问题. 配置与使用1.在applicatio ...
- springboot+thymeleaf+pageHelper带条件分页查询
html层 <div> <a class="num"><b th:text="'共 '+ ${result.resultMap['pages ...
- java+springBoot+Thymeleaf+vue分页组件的定义
导读 本篇着重介绍java开发环境下,如何写一个vue分页组件,使用到的技术点有java.springBoot.Thymeleaf等: 分页效果图 名称为vuepagerbasic的分页组件,只包含上 ...
- layui表格数据渲染SpringBoot+Thymeleaf返回的数据时报错(Caused by: org.attoparser.ParseException: Could not parse as expression: ")
layui table渲染数据时报错(Caused by: org.attoparser.ParseException: Could not parse as expression: ") ...
- Thymeleaf前后端分页查询
分页查询是一个很常见的功能,对于分页也有很多封装好的轮子供我们使用. 比如使用mybatis做后端分页可以用Pagehelper这个插件,如果使用SpringDataJPA更方便,直接就内置的分页查询 ...
- 权限管理系统之SpringBoot集成LayUI实现后台管理首页
万事开头难,昨天一直在构思用户权限管理系统怎么实现,实现哪些需求,采用什么技术等,也在网上百度了好多,计划使用SpringBoot + Mybatis + thymeleaf + LayUI + S ...
- LayUI分页,LayUI动态分页,LayUI laypage分页,LayUI laypage刷新当前页
LayUI分页,LayUI动态分页,LayUI laypage分页,LayUI laypage刷新当前页 >>>>>>>>>>>> ...
- org.springframework.expression.spel.SpelEvaluationException: EL1004E: Method call: Method service() cannot be found on com.my.blog.springboot.thymeleaf.util.MethodTest type
前言 本文中提到的解决方案,源码地址在:springboot-thymeleaf,希望可以帮你解决问题. 至于为什么已经写了一篇文章thymeleaf模板引擎调用java类中的方法,又多此一举的单独整 ...
- SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页
SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页 **SpringBoot+Mybatis使用Pagehelper分页插件自动分页,非常好用,不用在自己去计算和组装了. ...
随机推荐
- [React Hooks长文总结系列一]初出茅庐,状态与副作用
写在开头 React Hooks在我的上一个项目中得到了充分的使用,对于这个项目来说,我们跳过传统的类组件直接过渡到函数组件,确实是一个不小的挑战.在项目开发过程中也发现项目中的其他小伙伴(包括我自己 ...
- 启用reuse_port参数让Nginx性能提升3倍
为什么启用 reuse_port 记得 2008 年做性能测试的时候,新进7台 lenovo 4核4G 服务器用于性能测试. 当时资源紧张,这7台服务器都装了双系统(Win2003/CentOS5)空 ...
- 2020牛客NOIP赛前集训营-普及组(第二场)A-面试
面 试 面试 面试 题目描述 牛牛内推了好多人去牛客网参加面试,面试总共分四轮,每轮的面试官都会对面试者的发挥进行评分.评分有 A B C D 四种.如果面试者在四轮中有一次发挥被评为 D,或者两次发 ...
- MySQL提升笔记(4)InnoDB存储结构
这一节本来计划开始索引的学习,但是在InnoDB存储引擎的索引里,存在一些数据存储结构的概念,这一节先了解一下InnodDB的逻辑存储结构,为索引的学习打好基础. 从InnoDB存储引擎的存储结构看, ...
- Horovod Install
Horovod documentation 安装 [Step1]安装Open MPI 注意: Open MPI 3.1.3 安装有些问题, 可以安装 Open MPI 3.1.2 或者 Open MP ...
- 浅谈在c#中使用Zlib压缩与解压的方法
作者:Compasslg 介绍 近期用c#开发一个游戏的存档编辑工具需要用 Zlib 标准的 Deflate 算法对数据进行解压. 在 StackOverflow 上逛了一圈,发现 c# 比较常用到的 ...
- 太全了!Redis主从复制原理以及常见问题总结
相信很多小伙伴都已经配置过主从复制,但是对于redis主从复制的工作流程和常见问题很多都没有深入的了解.这次给大家整理一份redis主从复制的全部知识点. 下方可视频观看,效果更佳 Redis实战精讲 ...
- Django--虚拟环境、项目和应用的创建
第一点:官方手册 -- https://yiyibooks.cn/ 第二点:运行环境 -- django项目采用虚拟运行环境 之前我们pip install都是在Python的安装目录(底层)上安装的 ...
- Laravel 定时任务 任务调度 可手动执行
1.创建一个命令 php artisan make:command TestCommand 执行成功后会提示: Console command created successfully. 生成了一个新 ...
- 【Nacos】Springboot整合Nacos配置中心(二) 多环境配置
本篇随笔接上一篇文章:Springboot整合Nacos配置中心(一),主要记录Nacos多环境的配置的方法 Nacos多环境的配置 方法一: 1.在项目中的bootstrap.yaml文件中配置激活 ...