layUI的分页不起作用
问题:点击页数无效,问题在总条数
1.前端分页传的是page,limit.
2.前端jq
layui.use(['form', 'table'], function () { var $ = layui.jquery, form = layui.form, table = layui.table; table.render({ elem: '#currentTableId', url: '/tuserList', toolbar: '#toolbarDemo', defaultToolbar: ['filter', 'exports', 'print', { title: '提示', layEvent: 'LAYTABLE_TIPS', icon: 'layui-icon-tips' }], cols: [[ {type: "checkbox", width: 50}, {field:'id', width:150, title: 'ID', sort: true}, {field: 'username', width: 150, title: '用户名'}, {field: 'number', width: 150, title: '账号', sort: true}, {field: 'phone', width: 150, title: '手机号码'}, {field: 'email', title: '邮箱', minWidth: 150}, {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"} ]], limits: [10, 15, 20, 25, 50, 100], limit: 10, page: true, skin: 'line' }); // 监听搜索操作 form.on('submit(data-search-btn)', function (data) { var username=$("#username").val(); //执行搜索重载 table.reload('currentTableId', { page: { curr: 1 } , where: { username: username } }, 'data'); return false; });
3.controller的分页其中用到了分页插件PageHelper,因为框架的问题所以返回的结果类型要一致
/** * 使用分页插件获取用户的list * @return */ @RequestMapping(value = "/tuserList") @ResponseBody public JSONObject userList(HttpServletRequest request,TUser user, @RequestParam( required = false,value = "page",defaultValue = "1") int pageNum,@RequestParam( required = false,value = "limit",defaultValue = "10") int pageSize ){ JSONObject jsonObject=new JSONObject(); System.out.println(user.getUsername()); System.out.println(request.getParameter("username")); Listlist = userService.userPage(pageNum,pageSize,user); //使用分页插件 PageInfo pageInfo=new PageInfo<>(list); if (CollectionUtils.isNotEmpty(list)){ jsonObject.put("code",0); jsonObject.put("msg","请求成功"); jsonObject.put("count",pageInfo.getTotal()); jsonObject.put("data",pageInfo.getList()); } return jsonObject; }
4.service层
//用户的分页 public ListuserPage(int pageNum,int pageSize,TUser user);
5.serviceImpl层
@Override public ListuserPage(int pageNum,int pageSize,TUser user) { //查询出全部数据 PageHelper.startPage(pageNum,pageSize); List userList=baseMapper.userPage(user); return userList; }
6.mapper层
public ListuserPage(@Param("user") TUser user);
7.mapper.xml
8.maven插件包
<?xml version="1.0" encoding="UTF-8"?>xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.springframework.boot spring-boot-starter-parent 2.3.5.RELEASE com.jack travel 0.0.1-SNAPSHOT travel Demo project for Spring Boot 1.8 org.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-starter-web mysql mysql-connector-java runtime org.projectlombok lombok true com.baomidou mybatis-plus-boot-starter 3.2.0 com.baomidou mybatis-plus-generator 3.2.0 org.apache.velocity velocity-engine-core 2.0 org.freemarker freemarker 2.3.28 com.alibaba fastjson 1.2.47 org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-devtools true true com.github.pagehelper pagehelper-spring-boot-starter 1.2.13 org.springframework.boot spring-boot-maven-plugin org.projectlombok lombok
9.配置文件yml
server: port: 8081 servlet: context-path: / spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/db_travel?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true username: root password: 123456 jackson: date-format: yyyy-MM-dd HH:mm:ss time-zone: GMT+8 serialization: write-dates-as-timestamps: false # thymeleaf模板配置 thymeleaf: prefix: classpath:/templates/ suffix: .html mode: HTML5 encoding: UTF-8 cache: false #热部署 devtools: restart: enabled: true additional-paths: /** mybatis-plus: configuration: map-underscore-to-camel-case: true auto-mapping-behavior: full log-impl: org.apache.ibatis.logging.stdout.StdOutImpl mapper-locations: classpath*:mapper/**/*Mapper.xml global-config: # 逻辑删除配置 db-config: # 删除前 logic-not-delete-value: 1 # 删除后 logic-delete-value: 0 #分页pageHelper pagehelper: helper-dialect: mysql reasonable: true support-methods-arguments: true params: count=countSql