layui表格使用实例
layui表格使用实例
1、编写jsp页面
-
编写jsp页面
<%-- Created by IntelliJ IDEA. User: cheng Date: 2020/11/9 Time: 14:55 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <meta charset="utf-8"> <title>table模块快速使用</title> <link rel="stylesheet" href="${pageContext.servletContext.contextPath}/layui/css/layui.css" media="all"> </head> <body> <table id="demo" lay-filter="test"></table> <script src="${pageContext.servletContext.contextPath}/layui/layui.js"></script> <script> layui.use('table', function(){ var table = layui.table; //第一个实例 table.render({ elem: '#demo' ,height: 312 ,url: '${pageContext.servletContext.contextPath}/getData' //数据接口 ,page: true //开启分页 ,cols: [[ //表头 {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'} ,{field: 'title', title: '标题', width:200} ,{field: 'demoNumber', title: '数字', width:200, sort: true} ]] }); }); </script> </body> </html>
2、数据接口
-
新建controller,实现数据接口,返回json数据格式
package com.gec.oasys.controller; import com.gec.oasys.pojo.DemoBean; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @Controller public class LayuiTestController { @RequestMapping("/getData") @ResponseBody public Map<String,Object> getData() { Map<String,Object> mapData=new HashMap<>(); //组装数据 List<DemoBean> demoBeanList=new ArrayList<>(); demoBeanList.add(new DemoBean(1,"标题一",10.00)); demoBeanList.add(new DemoBean(2,"标题一",10.00)); demoBeanList.add(new DemoBean(2,"标题一",10.00)); demoBeanList.add(new DemoBean(3,"标题一",10.00)); demoBeanList.add(new DemoBean(4,"标题一",10.00)); demoBeanList.add(new DemoBean(5,"标题一",10.00)); demoBeanList.add(new DemoBean(6,"标题一",10.00)); demoBeanList.add(new DemoBean(7,"标题一",10.00)); mapData.put("data",demoBeanList); mapData.put("code","0"); mapData.put("msg",""); return mapData; } }
记得快乐
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!