When I send a request from JSP FORM, the server side automatically parses data to my ModelObject. But when I send requests from Backbone save() my ModelObject is empty on Server Side. How can I do it like as JSP FORMs?
@RequestMapping(value = "/member/ajax*", method = RequestMethod.POST)
public void onSubmitAjax(Member member, HttpServletResponse response, HttpServletRequest request) throws Exception {
//member is empty
memberManager.saveMember(member);
}
when I use GET it's working on Client Side:
@RequestMapping(value = "/member/ajax*", method = RequestMethod.GET)
public
@ResponseBody
Member showForm(@RequestParam(required = false) Long id, HttpServletRequest request) throws Exception {
Member member = memberManager.getMember(id);
return member;
}
I wrote a Spring MVC 3.1 backend for Backbone.JS Todo sample application. The code of the CRUD Controller may help you.
Based on your code sample, I think you should check that you have Jackson in your project dependencies, and use the following annotations for your onSubmitAjax method:
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json") @ResponseStatus(HttpStatus.CREATED) @ResponseBody
You should also try RESThub, a nice Spring + Backbone.js stack provided with documentation, tutorial and code samples (Disclaimer: I am RESThub lead developer).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With