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分页插件自动分页,非常好用,不用在自己去计算和组装了. ...
随机推荐
- java例题_47 读取 7 个数(1—50)的整数值,每读取一个值,程序打印出该值个数的*
1 /*47 [程序 47 打印星号] 2 题目:读取 7 个数(1-50)的整数值,每读取一个值,程序打印出该值个数的*. 3 */ 4 5 /*分析 6 * 1.多次读取---for循环 7 * ...
- Vue组件(35)动态组件 component 的 is 到底可以是啥?
component 动态组件 Vue官网上提供了一个动态组件 <component :is="currentTabComponent"> ,那么这里的 is 到底是什么 ...
- Linux标准输入、重定向与参数传递
Linux标准输入.重定向与参数传递 按惯例,每当运行一个新程序时,所有shell都为其打开3个文件描述符,即标准输入.标准输出以及标准错误.如果不做特殊处理,例如就像简单的命令ls,则这三个描述符都 ...
- Jenkins教程:使用Jenkins进行持续集成
[注]本文译自: https://www.edureka.co/blog/jenkins-tutorial/ 本文将重点介绍 Jenkins 架构和 Jenkins 构建管道,并向您展示如何在 J ...
- [Fundamental of Power Electronics]-PART II-8. 变换器传递函数-8.1 Bode图回顾
8.0 序 工程设计过程主要包括以下几个过程: 1.定义规格与其他设计目标 2.提出一个电路.这是一个创造性的过程,需要利用工程师的实际见识和经验. 3.对电路进行建模.变换器的功率级建模方法已经在第 ...
- 使用python制作大数据词云
1 from wordcloud import WordCloud 2 import PIL.Image as image 3 import numpy as np 4 import jieba 5 ...
- 201871030117-李亚楠 实验三 结对项目—《D{0-1}KP 实例数据集算法实验平台》项目报告
项目 内容 课程班级博客链接 课程班级 这个作业要求链接 作业要求 我的课程学习目标 1.体验软件项目开发中的两个人合作.练习结对编程:2.掌握Github协作开发程序的操作方法:3.熟悉编程语言的综 ...
- Kafka分片存储、消息分发和持久化机制
Kafka 分片存储机制 Broker:消息中间件处理结点,一个 Kafka 节点就是一个 broker,多个 broker 可以组成一个 Kafka集群. Topic:一类消息,例如 page vi ...
- 神奇的魔方阵--(MagicSquare)(2)
在上一篇博客中,我们讨论了阶数为奇数,以及阶数为(4K)的魔方阵的排列规则,以及代码实现(详见:https://www.cnblogs.com/1651472192-wz/p/14640903.htm ...
- Linux入门之基本的概念、安装和操作
目录 Linux基本概念 Linux的安装 虚拟机安装CentOS7 CentOS设置网络 Linux基本操作命令 文件目录操作命令 进程操作命令 文本操作命令 Linux权限操作 用户和组操作命令 ...