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分页插件自动分页,非常好用,不用在自己去计算和组装了. ...
随机推荐
- frp穿透内网使用vsftpd服务
本篇文章将会介绍如何使用frp穿透内网以及如何在centos8环境下安装和使用vsftpd,最后在公网通过frp穿透内网使用ftp. 一.内网穿透神器frp frp 是一个专注于内网穿透的高性能的反向 ...
- Android控件 之 TextClock & AnalogClock(模拟时钟)
TextClock •简介 关于时间的文本显示,Android 提供了 DigitalClock 和 TextClock. DigitalClock是Android第1版本发布,功能很简单,只显示时间 ...
- PE学习前的一些小知识
位移运算 1.与运算 & 2.或运算 | 3.非运算 ~ 4.异或运算 ^ 5.移位运算 << >> 内存分配,文件读写 宏定义说明 一.无参数的宏定义的一般形式为: ...
- CSS 文字装饰 text-decoration & text-emphasis
在 CSS 中,文字算是我们天天会打交道的一大类了,有了文字,则必不可少一些文字装饰. 本文将讲讲两个比较新的文字装饰的概念 text-decoration 与 text-emphasis,在最后,还 ...
- Database | 浅谈Query Optimization (1)
综述 由于SQL是声明式语言(declarative),用户只告诉了DBMS想要获取什么,但没有指出如何计算.因此,DBMS需要将SQL语句转换成可执行的查询计划(Query Plan).但是对同样的 ...
- 软工AI Bot NABCD分析
目标: 打造一个基于大数据的 IT 问答机器人服务,通过运用人工和AI 技术,极大提高问答产品的用户满意度. 适合高校<软件工程>,<人工智能>课程作为结对编程或者团队项目. ...
- spring-cloud-gateway 服务网关
Spring Cloud Gateway是Spring Cloud官方推出的第二代网关框架,取代Zuul网关.网关作为流量的,在微服务系统中有着非常作用,网关常见的功能有路由转发.权限校验.限流控制等 ...
- Recoil Input 光标位置被重置到末尾的问题
考察如下代码,页面中有个输入框,通过 Recoil Atom 来存储输入的值. App.tsx function NameInput() { const [name, setName] = useRe ...
- malloc函数详解 glibc2.27
malloc 函数分析(glibc.2.27) 本人菜一只,如果分析的有错误,请大佬指正. __libc_malloc函数分析 void * __libc_malloc (size_t bytes) ...
- Throwing cards away I UVA - 10935
Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the botto ...