I want to make a POST request through AJAX, and I also want to bind the whole class object to the request, and I want to receive that request with @requestParam
annotation. I know it can be done with @requestBody
annotation, but I am curious to know: can we do it with @requestParam
annotation?
An Ajax code:
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)
{
}
I do have RestDTO
Class RestDTO
{
int id;
String name;
//getter and setter
}
In controller
public String content(@RequestParam RestDTO restDTO){...}
What should I do the make this code run?
What should I change in sending data from ajax?
Do I need to change on server to receive an RestDto object with @requestParam
annotation?