Spring Learning Requestmapping

Source: Internet
Author: User

1: @RequestMapping: There are 6 properties to handle requests for address mapping?

' Value:url address

Method:get/post/put/delete

Consumes:: Specifies the submission to process the request (Content-type), for example: Application/json, text/html

Produces: Specifies the type of content returned, only if the request's accept type contains the specified type.

Parameters: Specifies which parameters must be included in the request for this processing

Requestmapping (value= "Testparams", params={"param1=value1", "param2", "!PARAM3"}) the value of/param1 must wait

In value1, the parameter param2 must exist, the value does not matter, the parameter param3 must not exist

Headers: Specifies that certain header values must be included in the request for the method to handle

2: @Resource @Autowired

is used when the bean is injected.

Same point: Both are written in the field or Setter method.

Differences: @AutoWired By default is Bytype assembly, by default the bean must be present, and requered=false can be used to indicate that the Allow is null.

If it is an byname (ID) assembly, it can be used in conjunction with @Qualifier annotations.

@Resource is automatically injected by byname (Bean ID) By default, and can be specified by using the name and type attributes.

3:spring MVC Other common annotations

@ModelAttribute

This was examined during an AC interview: When we request/mytest/sayhello.do, the method of using @ModelAttribute tag is executed first, and then the object returned is stored in the model. When the final access to the SayHello method is reached, the method parameters using the @ModelAttribute tag can be injected with the correct value.

@SessionAttributes

@Controller
@RequestMapping ("/mytest")
@SessionAttributes (value={"Intvalue", "StringValue"}, Types={user. class})

Specifies that the attribute is intvalue or stringvalue or that the type is User is placed in the session.

@PathVariable: Variables in Request parameters

@RequestParameter: Three common parameters: defaultvalue= "xx"/required=false/value= "xxx"

@ResponseBody: The formation returned by the Controller method is written to the body data area of the response object after it is converted to the specified format by the appropriate httpmessageconverer. When the return is jason/xml and so on.

@Component

@Repository: Used on the DAO layer
@CookieValue:

@RequestHeader: Bind the value on the header to the parameter

@RequestBody: This annotation is often used to deal with Content-type: not application/x-www-form-urlencoded encoded content, such as application/json,application/xml, etc.;

It is configured by using Handleradapter HttpMessageConverters to parse the postdata body and then bind to the corresponding bean.

Spring Learning Requestmapping

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.