Spring句柄jQuery可排序

时间:2015-05-13 09:50:22

标签: spring spring-mvc jquery-ui-sortable

我正在使用jQuery排序,就像在https://jqueryui.com/sortable/中一样。我的序列化和发送到服务器的代码如下:

$(function() {
    $( "#sortable" ).sortable({
        update: function (event, ui) {
            var data = $(this).sortable('serialize');
            $.ajax({
                //data: data,
                type: 'GET',
                url: '/categoryId/order?order=' + data
            });
        }
    });
    $( "#sortable" ).disableSelection();
});

在Spring方面,我的方法签名是:

@RequestMapping(value = "/{categoryId}", method = RequestMethod.GET)
public ModelAndView saveOrder(HttpServletRequest request, @RequestParam("order") List<String> order, @PathVariable("categoryId") String categoryId) throws Exception {

然而,我无法将发送的订单处理到列表中。我在浏览器上遇到400(错误请求)错误:

  

必需列表参数'order'不存在

来自浏览器的电话是:

/的categoryId顺序[] = 1&安培;顺序[] = 0&安培;顺序[] = 2及顺序[] = 3及顺序[] = 4和;为了[] = 5

2 个答案:

答案 0 :(得分:0)

@RequestParam("order")替换为@RequestParam("order[]")

/categoryId?order[]=1&order[]=0&order[]=2&order[]=3&order[]=4&order[]=5替换为/categoryId?order=1&order=0&order=2&order=3&order=4&order=5

答案 1 :(得分:0)

var data = sortable(&#39; serialize&#39;)它返回String,所以使用@RequestParam(&#34; data&#34;)String s;