I am trying to make a getJSON sending data to a Spring Server.
jQuery code:
$.getJSON('updateoneposto/',json, function (value) { // alert('Updated response='+value); });
The "data sent" is the json variable.
This is an screenshot example of the GET:
Spring Controller method code:
@RequestMapping(value = "updateoneposto", method = RequestMethod.GET) public void updateOnePosto(/*@PathVariable("data") String data*/) { System.out.println("I received something"); }
Where is the sent data from the GET (json variable). Is in the Body? If i try to get like a PathVariable it doesnt work. Anyone knows wchich is the correct way to get this data on the server?
It must to be a GET. A POST is not a possibility for me in this case.
You'd be looking for @RequestParam. @PathVariable
only applies when it is part of the path, as the data is after the ?
and is therefore a parameter or part of the query string according to standard URL format.
If you want to get all the data at once then there may be an annotation for that but it would probably be simpler to just pull it out of the request directly since the framework wouldn't be doing much for you at that point unless you're looking to connect a handler to deserialize the data (and this API smells a bit so I'd argue it's better to keep it lower level and more obviously a weaker contract). If you add the Request to the method signature Spring will automatically pass it to the method.