This is used in the foreground to initiate the request handler, background forgery data response to the front desk,
Solution: Erase the previous viewresolver, and configure the handler information for the corresponding request requests as follows
Before the handler returned is directly the logical view name, and need to configure the corresponding fixed view resolver, not very convenient, this time need to return object, make handler more flexible.
Since the value after return is no longer a logical view name, let @responsebody help.
Here are two new annotations:
@RequestBody convert the HTTP request body to the appropriate Httpmessageconverter object.
The @ResponseBody returns the content or object as the HTTP response body, and calls the adapter transform object that is appropriate for Httpmessageconverter to write to the output stream.
Httpmessageconverter interface, you need to turn on <mvc:annotation-driven/>.
The annotationmethodhandleradapter will initialize 7 converters, which can be initialized by calling Annotationmethodhandleradapter 's Getmessageconverts () method to get a collection of converters list
List
Reference
Bytearrayhttpmessageconverter Stringhttpmessageconverter Resourcehttpmessageconverter SourceHttpMessageConverter Xmlawareformhttpmessageconverter Jaxb2rootelementhttpmessageconverter Mappingjacksonhttpmessageconverter
It can be understood that, as long as there is a corresponding protocol parser, you can pass a few lines of configuration, a few annotations to complete the protocol-the transformation of the object work!
Ps:spring the default JSON protocol parsing is done by Jackson.
1 @Controller2 Public classMycontroller {3 //Processor Method4@RequestMapping (value= "/first.do")5 @ResponseBody6 PublicObject Dofirst () {7 return1;8 }9 Ten //Processor Method-----String One@RequestMapping (value= "/second.do", produces= "Text/html;charset=utf-8") A @ResponseBody - PublicObject Dosecond () { - the returnChinese characters; - } - - + //Processor Method-----UserInfo -@RequestMapping (value= "/third.do") + @ResponseBody A PublicObject Dothird () { atUserInfo info=NewUserInfo (); -Info.setage (12); -Info.setname ("Happy"); - returninfo; - } - in //Processor Methods-----Map -@RequestMapping (value= "/four.do") to @ResponseBody + PublicObject Dofour () { -UserInfo info=NewUserInfo (); theInfo.setage (12); *Info.setname ("Happy"); $ Panax Notoginseng -Map<string,userinfo> map=NewHashmap<string,userinfo>(); theMap.put ("Info", info); + returnmap; A } the + //Processor Method-----List -@RequestMapping (value= "/five.do") $ @ResponseBody $ PublicObject dofive () { -UserInfo info=NewUserInfo (); -Info.setage (12); theInfo.setname ("Happy"); - Wuyi theList<userinfo> list=NewArraylist<userinfo>(); - List.add (info); Wu returnlist; - } About}
These handler are all applicable to Ajax requests. You do not specify return view information.
Spring MVC Third Day "annotation implementation SPRINGMVC handler return value to object Configuration"