SpringMVC接收Javascript数组参数_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > SpringMVC接收Javascript数组参数

SpringMVC接收Javascript数组参数

 2018/1/17 6:57:02  umgsai  程序员俱乐部  我要评论(0)
  • 摘要:前端使用了JqueryDatatables插件,代码如下<tableclass="display"id="countTable"><thead><tr><th>接口类型</th><th>完成率</th><th>总数</th><th>成功</th><th>失败</th><th>执行中</th><th>
  • 标签:MVC 数组 Java Spring javascript

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

class="html"><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;
}

?

上一篇: java调用js脚本语言 下一篇: 没有下一篇了!
发表评论
用户名: 匿名