This article is very clear about spring's MVC @RequestMapping, Memo notes.
@Controller
@RequestMapping ("/appointments")
public class Appointmentscontroller {
Private final AppointmentBook AppointmentBook;
@Autowired
Public Appointmentscontroller (AppointmentBook appointmentbook) {
This.appointmentbook = AppointmentBook;
}
@RequestMapping (method = Requestmethod.get)
Public map<string, appointment> get () {
return Appointmentbook.getappointmentsfortoday ();
}
@RequestMapping (value= "/{day}", method = Requestmethod.get)
Public map<string, appointment> getforday (@PathVariable @DateTimeFormat (Iso=iso. Date Date day, model model) {
Return Appointmentbook.getappointmentsforday (day);
}
@RequestMapping (value= "/new", method = Requestmethod.get)
Public Appointmentform Getnewform () {
return new Appointmentform ();
}
@RequestMapping (method = Requestmethod.post)
Public String Add (@Valid appointmentform appointment, bindingresult result) {
if (Result.haserrors ()) {
return "Appointments/new";
}
Appointmentbook.addappointment (appointment);
return "Redirect:/appointments";
}
}
Dispatcherservle < servlet >
< Servlet-name > Dispatcher </servlet-name >
< Servlet-class > Org.springframework.web.servlet.DispatcherServlet </servlet-class >
< Load-on-startup > 1 </load-on-startup >
</servlet >
< servlet-mapping >
< Servlet-name > Dispatcher </servlet-name >
< Url-pattern >*. Do </Url-pattern >
</servlet-mapping >
/appointments/new.do
The mapping method is Getnewform ()
/appointments.do
Get request mapping method is get ()
The POST request mapping method is add (@Valid appointmentform appointment, bindingresult result)
Narrowing path mapping by parameter conditions
@RequestMapping (value = "/path", params= "Myparam=myvalue") public
Void Add () {...}
Http://localhost:8080/DynamicWebProject/hao/hello.do?myParam=myValue
Methods that are allowed to access path mappings only if there is a myparam=myvalue parameter in the URL
@RequestMapping (value = '/path ', method = Requestmethod.post, headers= ' content-type=text/* ') public
Void Add () {... }
The Add () method can only be accessed if a POST request with content-type=text/* (Content-type=text/xml) is included in the header information of the URL
Methods or annotations used in conjunction with @requestmapping
Org.springframework.web.context.request.WebRequest or Org.springframework.web.context.request.NativeWebRequest. Universal request parameters allow access to the Request/session property to the native Servlet/portlet API.
Java.util.Locale the locale of the current request, which provides the most specific locale by the parser.
Java.io.inputstream/java.io.reader the content of the access request. This value is the original Inputstream/reader, which is exposed by the Servlet API.
Java.io.outputstream/java.io.writer generates the content of the response. This value is the original Outputstream/writer, which is exposed by the Servlet API.
@ pathvariable Note Gets the parameters of the URI template variable.
@ requestparam to get the parameters for a particular servlet request parameter.
@ requestheader access to the parameters of the HTTP headers of a particular servlet request. The parameter value is converted to the parameter type of the declared method.
@ requestbody accesses HTTP request body parameters. The parameter value is converted to the parameter type of the declared method using Httpmessageconverters.
Httpentity <. > Access the HTTP Headers and contents of the servlet request. The request stream will be converted to an entity using Httpmessageconverters.
Java.util.map/org.springframework.ui.model/org.springframework.ui.modelmap is a rich implicit model, exposed to Web view
Org.springframework.validation.errors/org.springframework.validation.bindingresult
Org.springframework.web.bind.support.SessionStatus
Transferred from http://www.blogjava.net/wmcoo/articles/333428.html