In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of the role of @ RestController in SpringBoot http, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading what the role of @ RestController in SpringBoot http is. Let's take a look at it.
@ RestController
@ RestController = @ Controller + @ ResponseBody is composed of two comrades on the right side of the equal sign to briefly introduce two sentences to understand the meaning of our @ RestController:
Controller injects the currently decorated class into the SpringBoot IOC container so that the class is instantiated during the run from the project in which the class is located. Of course, it also has the function of semantics, that is, it means that this class acts as a Controller.
In a nutshell, the function of @ ResponseBody refers to the data returned by all API APIs in this class. Regardless of whether your corresponding method returns Map or other Object, it will be returned to the client in the form of a Json string. I have tried it. If String is returned, it is still String.
@ RestController@RequestMapping ("test") public class SampleController {
@ GetMapping public Map testGet () {
Return new HashMap () {{
Put ("name", "springboot")
}}
}
@ GetMapping (path = "str")
Public String testGetStr () {return "OK";}}
This code returns JSON String for Map and still String for String
When @ RestController is replaced with @ Controller, the return value for / test is as follows:
As you can see from the error report, when @ Controller modifies, Spring thinks it will return a View (that is, the C in MVC), but what is returned is a Map.
This is the end of the article on "what is the role of @ RestController in SpringBoot http". Thank you for reading! I believe you all have a certain understanding of the knowledge of "what is the role of @ RestController in SpringBoot http". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.