Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Format of @ Controller and @ RestController and @ GetMapping and @ PostMapping receive parameters in java

Shulou Source: shulou.com Published: 2022-06-02 04:44:59 10月16日 Update

This article mainly explains the format of @ Controller and @ RestController and @ GetMapping and @ PostMapping receiving parameters in java. The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn the format of @ Controller and @ RestController and @ GetMapping and @ PostMapping receiving parameters in java.

One, one. Using the @ Controller annotation, the view parser can parse the jsp,html page of return and jump to the corresponding page on the corresponding method

If you return json and other content to the page, you need to add @ ResponseBody annotation.

2.@RestController annotations are equivalent to the combination of @ Controller+@ResponseBody annotations. To return json data, you do not need to add @ ResponseBody annotations in front of the method, but using @ RestController annotations, you cannot return jsp,html pages, and the view parser cannot parse jsp,html pages.

II.

1. @ RequestMapping default method is supported by get,post.

2. @ RequestMapping (value = "createPickOrder.do", produces = "application/json;charset=utf-8", method = RequestMethod.POST)

Produces = "application/json;charset=utf-8": indicates the format of returned data

Method = RequestMethod.POST indicates the request format

Post request, if it is in json format (the transmission parameter is required to be json (application/json;charset=utf-8), the receiving parameter is either a parameter or an object and the parameter is preceded by @ RequestBody annotation); if it is a form submission (application/x-www-form-urlencoded), the receiving parameter can be either an object or multiple parameters.

Get request. Parameters cannot be in json (application/json;charset=utf-8) format, but can only be in form (application/x-www-form-urlencoded) format.

3 、

@ PostMapping

Map a POST request

New features of Spring MVC

Provides support for Restful style

@ GetMapping to process get requests

@ PostMapping to process post requests

@ PutMapping to process put requests

@ DeleteMapping to process delete requests

@ PostMapping (value = "/ user/login")

Equivalent to

@ RequestMapping (value = "/ user/login", method = RequestMethod.POST)

Click to enter

Thank you for your reading. The above is the content of @ Controller and @ RestController and @ GetMapping and @ PostMapping receiving parameter formats in java. After the study of this article, I believe you have a deeper understanding of the format of @ Controller and @ RestController and @ GetMapping and @ PostMapping receiving parameters in java, and the specific usage still needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Parameters formatting annotations pages processing content learning objects data methods methods forms views support two or more that is ideas situations articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Tech Info Apple OPPO Reno Linux