@PostMapping("findAll") @ResponseBody public Layui findAll(Param param){ QueryWrapper<EduTeacher> wrapper = new QueryWrapper<>(); Page<EduTeacher> page = new Page<>(param.getPage(),param.getLimit()); if(param.getA() != null && param.getA() != "") { wrapper.eq("name",param.getA()); } eduTeacherService.page(page,wrapper); //List<EduTeacher> list = eduTeacherService.list(wrapper); List<EduTeacher> records = page.getRecords(); long total = page.getTotal(); Layui data = Layui.data(Math.toIntExact(total),records); return data; } @PostMapping("delete") @ResponseBody public String delete(@RequestBody Param param){ QueryWrapper<EduTeacher> wrapper = new QueryWrapper<>(); if(param.getName() != null && param.getName() != "") { wrapper.eq("name",param.getName()); } boolean result = eduTeacherService.remove(wrapper); return "delete success"; }
layui工具类
package com.baomidou.springboot.util; import java.util.HashMap; import java.util.List; public class Layui extends HashMap<String, Object> { public static Layui data(Integer count, List<?> data){ Layui r = new Layui(); r.put("code", 0); r.put("msg", ""); r.put("count", count); r.put("data", data); return r; } }
html
<form class="layui-form layui-row layui-col-space16"> <div class="layui-col-md4"> <div class="layui-input-wrap"> <div class="layui-input-prefix"> <i class="layui-icon layui-icon-username"></i> </div> <input type="text" name="A" value="" placeholder="Field A" class="layui-input" lay-affix="clear"> </div> </div> <div class="layui-col-md4"> <div class="layui-input-wrap"> <input type="text" name="B" placeholder="Field B" lay-affix="clear" class="layui-input"> </div> </div> <div class="layui-col-md4"> <div class="layui-input-wrap"> <div class="layui-input-prefix"> <i class="layui-icon layui-icon-date"></i> </div> <input type="text" name="C" readonly placeholder="Field C" class="layui-input demo-table-search-date"> </div> </div> <div class="layui-btn-container layui-col-xs12"> <button class="layui-btn" lay-submit lay-filter="demo-table-search" id="search">Search</button> <button type="reset" class="layui-btn layui-btn-primary">Clear</button> </div> </form> <table class="layui-hide" id="ID-table-demo-search"></table>
表格渲染重载
layui.use(function(){ var table = layui.table; var form = layui.form; var laydate = layui.laydate; // 创建表格实例 table.render({ elem: '#ID-table-demo-search', url: 'http://localhost:8001/findAll', // 此处为静态模拟数据,实际使用时需换成真实接口 method: 'post', cols: [[ {type: 'radio', title: ' 标签:总结,表格,title,layui,param,field,table,data From: https://www.cnblogs.com/sgj191024/p/17992527