Preliminary knowledge: @RequestMappingRequestMapping is an annotation that handles request address mapping and can be used on classes or methods. On a class, the method that represents all response requests in a class is the parent path of the address. @RequestMapping (value = "/AAA")//Class level, you can have noPublicClassMycontroller {@RequestMapping (value = "/bbb")//Method level, you must havePublicString Getmyname () {Return "Myreturn"; }} The corresponding action is: <form action= "AAA/BBB" >The return page is myreturn.jsp@responsebody and @requestbody@responsebody means that the return result of the method is written directly to the HTTP response body, which is generally used when fetching data asynchronously. After using @requestmapping, the return value usually resolves to the jump path, plus @responsebody returns the result will not be resolved to the jump path, but is written directly to the HTTP response body. For example, asynchronously fetching JSON data, plus @responsebody, will return the JSON data directly. @RequestBody inserts the HTTP request body into the method, using the appropriate httpmessageconverter to write the request body to an object. function Login () {//Page asynchronous request var MyData = ' {' name ': ' ' + $ (' #name '). Val () + ' "," id ":" ' + $ (' #id '). Val () + ' "," status ":" ' + $ (' #status '). Val () + ' "}‘; $.ajax ({type: ' POST '), ContentType: ' Application/json ', url: "${pagecontext.request.contextpath}/person/login", ProcessData:False, DataType: ' JSON ', Data:mydata, success:function (data) {alert ("ID:" + data.id + "\nname:" + data.name + "\nstatus:" +Data.status); }, Error:function () {alert (' ERROR! ‘); } });}; @RequestMapping (value = "Person/login") @ResponseBodyPublic person Login (@RequestBody person person) {//Writes the MyData in the request to the Person objectreturn person;//is not resolved to a jump path, but is written directly to the HTTP response bodyExtension: @PathVariable Get Request Path variable function profile () {var url = "${pagecontext.request.contextpath}/person/profile/"; var query = $ (' #id '). Val () + '/' + $ (' #name '). Val () + '/' + $ (' #status ')). Val (); URL + = query; $.get (URL, function (data) {alert ("ID:" + data.id + "\nname:" + data.name + "\nsta Tus: "+ Data.status);}); @RequestMapping (value = "Person/profile/{id}/{name}/{status}" ) @ResponseBody public person Porfile (@PathVariable int ID, @PathVariable String name, @PathVariable Span style= "color: #0000ff;" >boolean status) {return new// @RequestMapping (value = "/person/profile/{id}/{name}/{status}") in {id}/{name}/{ Status} with the @pathvariable int ID, @PathVariable String name, @PathVariable boolean status one by one, matching by name.
@Responsebody and @requestbody