对应layui数据表格的数据接口(url)后台应该怎么写

前端:

<table id="cutSwitchAndKnifeGateTable" class="layui-table"
       lay-data="{url:'/handleCutSwitchAndKnifeGateTableData'}"
       lay-filter="cutSwitchAndKnifeGateTableEvent">
    <thead>
    <tr>
        <th lay-data="{field:'cutSwitchAndKnifeGate', width:'80%',event:'setCutSwitchAndKnifeGate',style:'cursor:pointer;'}">
            应拉断路器(开关)、隔离开关(刀闸)
        </th>
        <th lay-data="{field:'cutSwitchAndKnifeGate_impl', width:'20%', event: 'setCutSwitchAndKnifeGate_impl', style:'cursor: pointer;'}">
            已执行
        </th>
    </tr>
    </thead>
</table>

后端:

 @RequestMapping("/handleCutSwitchAndKnifeGateTableData")
    @ResponseBody
    private  Map<String,Object> handleCutSwitchAndKnifeGateTableData()
    {
        List<CutSwitchAndKnifeGateBean> cutSwitchAndKnifeGateBeanList=new ArrayList<>();
        int size=GlobalVariable.workOrderClass.getWorkOrderSafeMeasureCutSwitchAndKnifeGate().size();
        for (int i = 0; i <size; i++)
        {
            int a=i+1;
            CutSwitchAndKnifeGateBean cutSwitchAndKnifeGateBean=new CutSwitchAndKnifeGateBean();
            cutSwitchAndKnifeGateBean.setCutSwitchAndKnifeGate("("+a+")"+GlobalVariable.workOrderClass.getWorkOrderSafeMeasureCutSwitchAndKnifeGate().get(i));
            cutSwitchAndKnifeGateBean.setCutSwitchAndKnifeGate_impl("  ");
            cutSwitchAndKnifeGateBeanList.add(cutSwitchAndKnifeGateBean);
        }
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("msg","应拉断路器(开关)、隔离开关(刀闸)");
        map.put("count",size);
        map.put("data",cutSwitchAndKnifeGateBeanList);
        return map;

    }

总结:后端给前端传的数据是json数据,且需要按照这种规定的格式写,详情可见layui官方文档

你可能感兴趣的:(Layui)