SpringMVC前台传递数组,后台使用list接收

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/sutongxuevip/article/details/78594665

页面代码:(这里使用的是thymeleaf)

 <select  id="userList" name="multiple" multiple="multiple">
        <option  th:each="user:${userList}"  th:text="${user.loginid}"></option>
        <option  th:each="agent:${agentList}"  th:text="${agent.agentid}"></option>
 </select>

jQuery代码:

 queryParams = function (params) {
        var wholeTimeStamp = $('#time-range span').text();
        var startDate = wholeTimeStamp.substring(0, 16) + ":00";
        var endDate = wholeTimeStamp.substring(19, 35) + ":59";
        var action = $("#action option:selected").val();
        var selectedItem = [];
        $('#userList option:selected').each(function () {
              selectedItem .push($(this).text());
        });
        var temp = {
            limit: params.limit,
            offset: params.offset,
            startDate: startDate,
            endDate: endDate,
            action:action,
            selectedItem:selectedItem
        };
        return temp;
    };

 //得到选中的list
    function getSeletedItem(obj, targetList) {
        for (var i = 0; i < obj.options.length; i++) {
            if (obj.options[i].selected) {
                targetList.push(obj.options[i].value);// 收集选中项
            }
        }
        return targetList;
    }

后台Controller

 @GetMapping(value = "/getLogs")
    @ResponseBody
    public PageResult<AuditrailBo> getLogs(@RequestParam(value = "selectedItem[]", required = false) List<String> selectedItem, AuditrailVo auditrailVo, HttpServletRequest request) throws ParseException {

       
        if (selectedItem != null && selectedItem.size() > 0) {
            for (int i = 0; i < selectedItem.size(); i++) {
                System.out.println(selectedItem.get(i));
            }
        }
      
        return null;
    }


在传递String时 使用的是“=”

在传递数组时  使用的是“push”,          


上面就是全部代码。如有不明白可以留言一起讨论

展开阅读全文

没有更多推荐了,返回首页