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分页插件自动分页,非常好用,不用在自己去计算和组装了. ...
随机推荐
- 【原创】Linux虚拟化KVM-Qemu分析(十一)之virtqueue
背景 Read the fucking source code! --By 鲁迅 A picture is worth a thousand words. --By 高尔基 说明: KVM版本:5.9 ...
- 对接快递100&聚水潭API
对接快递100&聚水潭API 入我相思门,知我相思苦. 简介:对接第三方平台快递100&聚水潭API的简要总结. 1.感悟 个人感觉快递100的API更友好一些,比如有SDK可以调用: ...
- 「HTML+CSS」--自定义加载动画【007】
前言 Hello!小伙伴! 首先非常感谢您阅读海轰的文章,倘若文中有错误的地方,欢迎您指出- 哈哈 自我介绍一下 昵称:海轰 标签:程序猿一只|C++选手|学生 简介:因C语言结识编程,随后转入计算机 ...
- [二分匹配]Asteroids
A s t e r o i d s Asteroids Asteroids 题目描述 Bessie wants to navigate her spaceship through a dangerou ...
- Hystrix熔断原理
Netflix的开源组件Hystrix的流程: 图中流程的说明: 将远程服务调用逻辑封装进一个HystrixCommand. 对于每次服务调用可以使用同步或异步机制,对应执行execute()或que ...
- java面试-对象的创建、内存布局、访问定位
一.对象的创建 1.虚拟机遇到一条new指令时,首先将去检查这个指令的参数是否能在常量池中定位到一个类的符号引用,并且检查这个符号引用代表的类是否已被加载.解析和初始化过.如果没有,那必须先执行相应的 ...
- MySQL常用配置参数说明
1.sync_binlog sync_binlog=0,当事务提交之后,MySQL不做fsync之类的磁盘同步指令刷新binlog_cache中的信息到磁盘,而让Filesystem自行决定什么时候来 ...
- 附031.Kubernetes_v1.20.4高可用部署架构二
kubeadm介绍 kubeadm概述 参考附003.Kubeadm部署Kubernetes. kubeadm功能 参考附003.Kubeadm部署Kubernetes. 本方案描述 本方案采用kub ...
- kubernetes 查看cpu,内存使用情况
kubectl top pod --all-namespaces kubectl top pod -n kubeflow
- .NET6 平台系列1 .NET发展史之.NET Framework简介
系列目录 [已更新最新开发文章,点击查看详细] 自1995年互联网战略日以来最雄心勃勃的事业 -- 微软.NET战略, 2000年6月30日. 微软公司于2002年2月13日正式推出第一代.N ...