Passing json object to spring mvc controller using Ajax -
i trying send json via ajax request spring mvc controller without success. json string has following form:
{"books": [{'author':'murakami','title':'kafka on shore'},{'author':'murakami','title':'norwegian wood'}]} the controller parses json wraps through java bean:
class books{ list <map<string, string>> books; //...get & set method of bean } the controller method has following form:
@requestmapping(method = { requestmethod.get, requestmethod.post }, value = "/checkbook.do") public modelandview callcheckbook( @requestbody books books){....} unfortunately not work, following error when invoking method: "null modelandview returned dispatcherservlet name..."
where getting wrong? thank in advance! regards
create model class
class books { private string author; private string title; // gets , sets } and create wrapper class this
class bookwrapper{ private list<books> books; // name should matches json header } now in controller
@requestmapping(method = { requestmethod.get, requestmethod.post }, value = "/checkbook.do") public modelandview callcheckbook( @requestbody bookwrapper books){....} in ajax call create seralizearray of forum give json object , bind wrapper class
Comments
Post a Comment