Introduction to Spring MVC (1) - Execution process and common annotations of Spring MVC

1. What is SpringMVC

SpringMVC is the mvc framework similar to Struts2, which belongs to the follow-up product of SpringFrameWork. The interactive part with the view layer in the model layer.

SpringMVC execution process:

 

2. Common Notes    

1. How to use the RequestMapping annotation class

  The attributes of the RequestMapping annotation class are value, method, consumes, produces, params, headers, and the value attribute is introduced here:

  Represents a specific request path, such as the above /user, /login are the value of the value
  value can be omitted, as in the example, directly use the format of @RequestMapping("/login"), which is equivalent to @RequestMapping(value = "/login")

 

例:@RequestMapping(value = "/login", method = {RequestMethod.POST, RequestMethod.GET}) 

consumes attribute: specify the submitted content type (Content-Type) of the request, such as application/json, text/html, its value can be either a string or an array

 

produces attribute:

Specifies that certain parameter values ​​must be included in the request to trigger this processing method.

params property:

Specify that the request must contain certain parameter values ​​to trigger this processing method
. In addition to the = equal sign, the != sign can also be used in the parameters, which means that the method
can be triggered if the parameter value is not equal to the specific parameter. Value, use the "paramName" format directly, which means that the request must contain a parameter named paramName.
Directly use the "!paramName" format to indicate that the request cannot contain a request parameter named paramName.

headers property:

The request header must contain certain specified parameter values ​​in order for this method to process the request

2. Knowledge points of RequestParam annotation class:

There are two main ways to obtain parameters in the SpringMVC background control layer, one is request.getParameter("name"), and the other is to use the annotation @RequestParam to directly obtain
three attribute values, required and defaultValue
without any parameters, indicating that The required parameter name is the same as the marked variable name.
You can use required=false or true to ask whether the front-end parameters configured by @RequestParam must be passed. The
parameter type should not use the basic types int, long, etc., but should use the specific object classes Integer, Long, String, etc.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325224500&siteId=291194637