SpringMVC接收Javascript数组参数

前端使用了Jquery Datatables插件,代码如下

<table class="display" id="countTable">
                    <thead>
                    <tr>
                        <th>接口类型</th>
                        <th>完成率</th>
                        <th>总数</th>
                        <th>成功</th>
                        <th>失败</th>
                        <th>执行中</th>
                        <th>平均时长(秒)</th>
                    </tr>
                    </thead>
                    <tbody>

                    </tbody>
                </table>
    function initCountTable() {
        var apiNameList = new Array();
        for (var i = 0; i < $("#orderTypeSelect option").length; i++) {
            var optionVal = $("#orderTypeSelect option").eq(i).val();
            if (optionVal == "") {
                continue;
            }
            var apiName = optionVal.split("|")[0];
            apiNameList.push(apiName);
        }
        $('#countTable').DataTable( {
            "ajax": {
                url: "/order/queryApiCount.json",
                data: {
                    apiNameList: apiNameList
                },
                type: "POST"
            },
            "columns": [
                { "data": "apiName" },
                { "data": "completionRate" },
                { "data": "totalCount" },
                { "data": "successCount" },
                { "data": "failCount" },
                { "data": "processingCount"},
                { "data": "averageSpendTime"}
            ],
            "bPaginate": false,//是否分页显示
            "searching": false,//是否展示搜索框
            "order": [[ 1, "desc" ]]//默认排序列
        });
    }

 后端使用SpringMVC接收参数

    @RequestMapping(value = "/order/queryApiCount.json", method = RequestMethod.POST)
    @ResponseBody
    public Object queryApiCount(@RequestParam("apiNameList[]") List<String> apiNameList) {
        Map map = Maps.newHashMap();
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        List<OrderCount> orderCountList = Lists.newArrayList();
        if (!CollectionUtils.isEmpty(apiNameList)) {
            //......省略部分代码
                orderCountList.add(orderCount);
            
        }
        map.put("data", orderCountList);
        return map;
    }

 数据模型

@Data
public class OrderCount {
    private String apiName;
    private String completionRate = "";
    private int totalCount;
    private int successCount;

    private int oneTimeSuccessCount;
    private int retrySuccessCount;

    private int failCount;
    private int processingCount;
    private double averageSpendTime;
}

猜你喜欢

转载自umgsai.iteye.com/blog/2407871