@ Responsebody and @ RequestBody, @ responsebody
Prerequisites: @ RequestMappingRequestMapping is an annotation for Processing request address ing and can be used for classes or methods. Used on the class to indicate that all methods in the class that respond to requests use this address as the parent path. @ RequestMapping (value = "/aaa") // class level. public class myController {@ RequestMapping (value = "/bbb") may not exist. // method level, public String getMyName () {return "myReturn" ;}} must correspond to the following actions: <form action = "aaa/bbb"> the return page is myReturn. jsp @ responsebody and @ RequestBody @ responsebody indicate that the returned results of this method are directly written into the HTTP response body, which is generally used for asynchronous data retrieval. After @ RequestMapping is used, the return value is usually parsed as a jump path. After @ responsebody is added, the returned result is not parsed as a jump path, but directly written into the HTTP response body. For example, json data is obtained asynchronously. After @ responsebody is added, json data is directly returned. @ RequestBody: insert the HTTP Request body into the method, and use the appropriate HttpMessageConverter to write the Request body to an object. Function login () {// asynchronous page 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 + "\ nstat Us: "+ data. status) ;}, error: function () {alert ('error! ') ;}}) ;};@ RequestMapping (value = "person/login") @ ResponseBody public Person login (@ RequestBody Person person) {// write the mydata in the request to return Person in the person object; // it will not be parsed as a jump path, but will be directly written into the HTTP response body} extension: @ PathVariable get the request PATH variable function profile () {var url = "$ {pageContext. request. contextPath}/person/profile/"; var query = $ ('# id '). val () + '/' + $ ('# name '). val () + '/' + $ ('# status '). val (); url + = query; $. ge T (url, function (data) {alert ("id:" + data. id + "\ nname:" + data. name + "\ nstatus:" + data. status) ;}) ;}@ RequestMapping (value = "person/profile/{id}/{name}/{status }") @ ResponseBody public Person porfile (@ PathVariable int id, @ PathVariable String name, @ PathVariable boolean status) {return new Person (id, name, status );} // @ RequestMapping (value = "/person/profile/{id}/{name}/{status}") {id}/{na Me}/{status} and @ PathVariable int id, @ PathVariable String name, @ PathVariable boolean status match by name.