Layui前後台互動資料擷取java

來源:互聯網
上載者:User

標籤:接收   tag   cxf   span   dia   lang   表資料   table   nts   

Layui簡介

Layui是一款適用於背景程式員的UI架構,學習成本低。Json資料格式互動前後台,並且也相當適用單頁面開發。有興趣的朋友可以看看layui官網。

Layui前後台資料互動

layui有自己的一套特定的資料格式互動(這很重要),必須參數code:0,msg:“”,count:資料size(int),data:”資料List”。一般我們選擇封裝返回接收類。 
Layui前台js請求資料 
其中 html代碼

<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代碼

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後台代碼

    @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工具類代碼

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在這裡可有可無,你們可以自行封裝

@Datapublic 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接受到的資料格式要為 

轉自78944591

Layui前後台互動資料擷取java

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.