Annotated controllers for Spring MVC

Spring MVC annotation test controller

 

development path

 

1. Before Spring 2.5, we defined our handler classes by implementing the Controller interface or its implementation. It has been deprecated.

 

 

2. pring 2.5 introduces annotated processor support, and defines our processor class through @Controller and @RequestMapping annotations.

And provides a powerful set of annotations :

 

@Controller: used to identify the processor class;

@RequestMapping: Mapping rules from requests to handler function methods;

@RequestParam: The binding of request parameters to the method parameters of the processor function processing method;

@ModelAttribute: Binding of request parameters to command objects;

@SessionAttributes: Attributes used to declare session-level storage, placed on the handler class, usually listed

The names corresponding to model attributes (such as @ModelAttribute), these attributes will be transparently saved to the session;

@InitBinder: Custom data binding registration support for converting request parameters to the corresponding types of command object properties;

 

 

3. Spring 3.0 introduces RESTful architectural style support (supported by @PathVariable annotation and some other features), and introduces more annotation support:

 

    @CookieValue: Binding of cookie data to the method parameters of the processor function processing method;

    @RequestHeader: The binding of the request header data to the method parameters of the processor function processing method;

    @RequestBody: Binding of the body of the request (type conversion through HttpMessageConverter);

    @ResponseBody: The return value of the processor function processing method is used as the response body (type conversion through HttpMessageConverter);

    @ResponseStatus: Define the status code and reason returned by the handler function processing method/exception handler;

    @ExceptionHandler: Annotated declaration of exception handler;

    @PathVariable: The template variable part of the request URI is bound to the method parameter of the processor function processing method, thereby supporting the URI of the RESTful architectural style;

 

 

4. Spring 3.1 uses the new HandlerMapping and HandlerAdapter to support @Contoller and @RequestMapping annotation processors.

 

      New @Contoller and @RequestMapping annotation support classes: The combination of handler mapping RequestMappingHandlerMapping and handler adapter RequestMappingHandlerAdapter replaces the handler mapping DefaultAnnotationHandlerMapping and handler adapter AnnotationMethodHandlerAdapter starting with Spring 2.5, providing more extension points.

 

 

 

The request mapping is divided into the following types:

 

      1. URL path mapping: a functional processing method that uses URL mapping requests to processors;

      2. Request method mapping limitation: if the function processing method is limited, only GET requests are processed;

      3. Request parameter mapping restriction: For example, it is restricted to only process requests containing the "abc" request parameter;

      4. Request header mapping restriction: For example, only requests with "Accept=application/json" are processed.

 

 

 

Remember the six parts of an http request

 

      1. The request method, such as GET or POST, indicates the method of submission;

      2. URL, the requested address information;

      3. Agreement and version;

      4. Request header information (including cookie information);

      5. Carriage Return Line Feed (CRLF);

      6. The request content area (that is, the requested content or data), such as the parameter data when the form is submitted, the URL request parameters (?abc=123?), etc.

 

Guess you like

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