`
umgsai
  • 浏览: 103609 次
  • 性别: Icon_minigender_1
  • 来自: 广州
文章分类
社区版块
存档分类
最新评论

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

 

分享到:
评论
1 楼 umgsai 2018-01-18  
https://www.zhihu.com/people/san-mao-87-10/answers

相关推荐

Global site tag (gtag.js) - Google Analytics