Spring Boot's entry controller common annotations

Source: Internet
Author: User

Common annotations for Controller

@Controller

  Handling HTTP Requests

@RestController

  Spring4 after the new annotation, the original return JSON data need @responsebody mate @controller, now merged into @restcontroller

@RequestMapping

  Configure URL mapping, value configuration URL method path, methods configuration request method, example:@RequestMapping (value= "Hello", method = Requestmethod.get)

@PathVariable

Gets the data in the URL, the URL of the request: URL path/value , example: HTTP://LOCALHOST:8080/HI/1, the request method is relative to @requestparam concise

  

@RequestParam

Gets the value of the request parameter, @RequestParam (value = "id", required = False,defaultvalue = "1") value is the parameter name, required = False does not have to pass in (default is True), DefaultValue default value when parameters are not passed in

Url method of the request: URL path? key=value Example: http://localhost:8080/hi?id=1

  

@GetMapping and @postmapping

Combining annotations, @GetMapping is equivalent to @requestmapping (method = Requestmethod.get), @PostMapping is equivalent to @requestmapping (method = Requestmethod.post)

That is, @getmapping receives a GET request, @PostMapping receives a POST request

  

Spring Boot's entry controller 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.