【发布时间】:2016-06-30 10:09:51
【问题描述】:
我想通过 AJAX 发出一个 POST 请求,我还想将整个类对象绑定到该请求,并且我想接收带有 @requestParam 注释的请求。我知道用@requestBody注解可以做到,但我很想知道:我们可以用@requestParam注解吗?
Ajax 代码:
var restDTO{
id: 3,
name: "hello"
}
$.ajax({
url: url,
type: 'POST',
dataType: 'json',
contentType: 'application/json',
mimeType: 'application/json',
data: JSON.stringify({RestDTO : restDTO}),
success: function(data)
{
}
我确实有 RestDTO
Class RestDTO
{
int id;
String name;
//getter and setter
}
在控制器中
public String content(@RequestParam RestDTO restDTO){...}
我应该怎么做才能使这段代码运行?
从 ajax 发送数据我应该改变什么?
我是否需要在服务器上进行更改以接收带有 @requestParam 注释的 RestDto 对象?
【问题讨论】:
标签: java json ajax spring spring-mvc