Introduction to Spring MVC (i)--SPRINGMVC implementation process and common annotations

Source: Internet
Author: User

First, what is SPRINGMVC

SPRINGMVC is similar to the STRUTS2 MVC framework, which belongs to the springframework of the following products. The interaction part of the view layer in the model layer.

SPRINGMVC Execution Process:

Second, commonly used annotations

1. How to use requestmapping annotation class

The properties of the Requestmapping annotation class, respectively, are value, method, consumes, produces, params, headers, which describes the Value property:

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

Example: @RequestMapping (value = "/login", method = {requestmethod.post, requestmethod.get})

Consumes property: Specifies the requested commit content type (Content-type), such as Application/json, text/html, whose value can be either a string or an array

Produces properties:

Specifies that some parameter values must be included in the request before this processing is triggered.

Params property:

Specifies that some parameter values must be included in the request to trigger this processing method
In addition to the = equals sign, you can use the! = number in the parameter to indicate that the value of the parameter is not equal to trigger the method
You can also use the "paramname" format without specifying a specific value, and the parameter named ParamName must be included in the request.
Use the "!paramname" format directly to indicate that a request cannot contain a request parameter named ParamName

Headers Properties:

The request header header must contain some specified parameter values in order for the method to process the request

2, Requestparam note class of knowledge points:

There are two main ways to get parameters in the SPRINGMVC background control layer, one is Request.getparameter ("name") and the other is to get directly with the annotation @requestparam
There are three properties of value, required, defaultvalue
Does not take any parameters, indicating that the required parameter name is the same as the label's variable name
Required=false or true can be used to require the @requestparam configuration of the front-end parameters must be transmitted
Parameter type try not to use basic type Int,long, etc., but should use specific object class integer, Long, string, etc.

Introduction to Spring MVC (i)--SPRINGMVC implementation process and common annotations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.