This content is @requestmapping, there will be an example code later
Spring MVC uses @RequestMapping annotations to specify which URL requests can be handled by the controller in terms of class definitions and method definitions of the Controller @requestmapping
@RequestMapping can not only modify the class, but also modify the method.
at the class definition : Provides preliminary request mapping information. The root directory relative to the WEB app
method : Provides further subdivision mapping information. Relative to the URL at the class definition. If @RequestMapping is not marked at the class definition, the URL marked at the method is relative to the Web app's root directory
Dispatcherservlet intercepts the request, it determines the processing method corresponding to the request through the mapping information provided by @RequestMapping on the controller.
Mapping request parameters, request methods, or request headers
@RequestMapping can use request methods, request parameters, and request header mapping requests in addition to request URL mapping requests
The value, method, params, and headers of the @RequestMapping respectively represent the request URL, request methods, request parameters, and the mapping condition of the request header, which is the relationship between them, and the combination of multiple conditions can make the request mapping more precise.
The params and headers support simple expressions:
PARAM1: Indicates that the request must contain a request parameter named param1
!PARAM1: Indicates that the request cannot contain a request parameter named param1
Param1! = value1: Indicates that the request contains a request parameter named param1, but its value cannot be value1
{"Param1=value1", "param2"}: The request must contain two request parameters named Param1 and param2, and the value of the param1 parameter must be value1
Instance Code
@RequestMapping ("/springmvc") @Controllerpublic class Requestmapper {private static final String success= "SUCCESS "; @RequestMapping (value="/testparamheader ", params={" username "," age!=10 "},headers=" accept-language=zh-cn,zh;q= 0.8 ") Public String Testparam () {System.out.println (" Testparam "); return SUCCESS;} @RequestMapping (value= "/testmethod", method=requestmethod.post) public String TestMethod () {System.out.println (" TestMethod "); return SUCCESS;} @RequestMapping ("/requestmap") public String Requestmap () {System.out.println ("Requestmapper"); return SUCCESS;}}
index.jsp
<%@ page language= "java" contenttype= "text/html; Charset=iso-8859-1 " pageencoding=" Utf-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
The result is still all mapped to the physical view of the success.jsp
SPRINGMVC Learning (ii)--using Requestmapper request mapping