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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值