Jquery 请求长文件的参数列表
eventIdsToDelete[“24616342”,“24615878”]我试图将长值列表发送到Spring控制器,但收到400个错误请求。所以我猜我的请求映射签名是不正确的 我的jQuery AJAX调用Jquery 请求长文件的参数列表,jquery,spring-mvc,Jquery,Spring Mvc,eventIdsToDelete[“24616342”,“24615878”]我试图将长值列表发送到Spring控制器,但收到400个错误请求。所以我猜我的请求映射签名是不正确的 我的jQuery AJAX调用 var myList = [24616342,24616201,24616310]; $.ajax({ url: '/myApp/path/toController', type: 'POST', data: {myList: JSON.stringify(myList)},
var myList = [24616342,24616201,24616310];
$.ajax({
url: '/myApp/path/toController',
type: 'POST',
data: {myList: JSON.stringify(myList)},
success: function(response) { ... }
});
我的请求映射
@RequestMapping(value = "/myApp/path/toController", method = RequestMethod.POST)
public @ResponseBody boolean doSomething(Model model, @RequestParam List<Long> myList)
{
System.out.println(myList);
return true;
}
我尝试将请求映射参数更改为
List<String>
列表
它工作得很好。但我希望请求映射方法类型为String。改为尝试@RequestBody
@RequestMapping(value = "/myApp/path/toController", method = RequestMethod.POST)
public @ResponseBody boolean doSomething(Model model, @RequestBody List<Long> data)
{
System.out.println(data);
return true;
}
@RequestMapping(value=“/myApp/path/toController”,method=RequestMethod.POST)
public@ResponseBody布尔doSomething(模型模型,@RequestBody列表数据)
{
系统输出打印项次(数据);
返回true;
}
通过以下更改解决
(a) jQuery调用
data: {myList: myList},
(b) 控制器方法
@RequestMapping(value = "/myApp/path/toController", method = RequestMethod.POST)
public @ResponseBody boolean doSomething(Model model, @RequestParam("myList[]") List<Long> myList)
{
System.out.println(myList);
return true;
}
@RequestMapping(value=“/myApp/path/toController”,method=RequestMethod.POST)
public@ResponseBody布尔doSomething(模型,@RequestParam(“myList[]”)列表myList)
{
System.out.println(myList);
返回true;
}
我使用@RequestParam本身,但我必须使用字符串类型而不是长类型。请参阅编辑后的文章。如何将参数设置为长类型列表而不是字符串类型。
@RequestMapping(value = "/myApp/path/toController", method = RequestMethod.POST)
public @ResponseBody boolean doSomething(Model model, @RequestParam("myList[]") List<Long> myList)
{
System.out.println(myList);
return true;
}