SpringMVC接收Javascript数组参数

阅读更多

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

接口类型 完成率 总数 成功 失败 执行中 平均时长(秒)

 

    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 apiNameList) {
        Map map = Maps.newHashMap();
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        List 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;
}

 

你可能感兴趣的:(java)