Layui先後臺交互數據獲取java

Layui簡介

Layui是一款適用於後臺程序員的UI框架,學習成本低。Json數據格式交互先後臺,而且也至關適用單頁面開發。有興趣的朋友能夠看看layui官網javascript

Layui先後臺數據交互

layui有本身的一套特定的數據格式交互(這很重要),必須參數code:0,msg:「」,count:數據size(int),data:」數據List」。通常咱們選擇封裝返回接收類。 
Layui前臺js請求數據 
其中 html代碼php

<link rel="stylesheet" href="static/layui/css/layui.css" media="all" /> <script type="text/javascript" src="static/layui/layui.js"></script> <table class="layui-hide" id="test" lay-filter="table"></table>
  • 1
  • 2
  • 3

js代碼css

layui.use(['form','layer','table'], function(){ var table = layui.table ,form = layui.form,$=layui.$; table.render({ elem: '#test' //綁定table id ,url:'sys/menu/list' //數據請求路徑 ,cellMinWidth: 80 ,cols: [[ {type:'numbers'} ,{field:'name', title:'菜單名稱'} ,{field:'parentName', title:'父菜單名稱',width:150} ,{field:'url', title: '菜單路徑'} ,{field:'perms', title: '菜單權限'} ,{field:'type', title:'類型'} ,{field:'icon', title:'圖標'} ,{field:'orderNum', title:'排序'} ,{fixed: 'right',title: '操做', width:180, align:'center', toolbar: '#toolBar'}//一個工具欄 具體請查看layui官網 ]] ,page: true //開啓分頁 ,limit:10 //默認十條數據一頁 ,limits:[10,20,30,50] //數據分頁條 ,id: 'testReload' }); });
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

java後臺代碼html

@RequestMapping("/list") @ResponseBody @RequiresPermissions("sys:menu:list") public Layui list(@RequestParam Map<String, Object> params){ //查詢列表數據 Query query = new Query(params); List<SysMenuEntity> menuList = sysMenuService.queryList(query); int total = sysMenuService.queryTotal(query); PageUtils pageUtil = new PageUtils(menuList, total, query.getLimit(), query.getPage()); return Layui.data(pageUtil.getTotalCount(), pageUtil.getList()); }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

Layui工具類代碼java

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; } }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

PageUtils在這裏無關緊要,大家能夠自行封裝程序員

@Data public class PageUtils implements Serializable { private static final long serialVersionUID = -1202716581589799959L; //總記錄數 private int totalCount; //每頁記錄數 private int pageSize; //總頁數 private int totalPage; //當前頁數 private int currPage; //列表數據 private List<?> list; /** * 分頁 * @param list 列表數據 * @param totalCount 總記錄數 * @param pageSize 每頁記錄數 * @param currPage 當前頁數 */ public PageUtils(List<?> list, int totalCount, int pageSize, int currPage) { this.list = list; this.totalCount = totalCount; this.pageSize = pageSize; this.currPage = currPage; this.totalPage = (int)Math.ceil((double)totalCount/pageSize); } }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

總之一句話,最後Layui接受到的數據格式要爲 
這裏寫圖片描述app

轉自https://blog.csdn.net/qq_26118603/article/details/78944591框架

相關文章
相關標籤/搜索