In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
The main content of this article is to explain "what notes are there in Spring to declare bean". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn "what are the annotations and statements of Spring bean"!
Bean comments
Spring provides several annotations declaring that bean is a Bean managed by Spring
@ Controller declares such things as a MVC class, which is usually used with @ RequestMapping
@ Service declares that this class is a business processing class, usually used with @ Transactional
@ Component General comment
@ Repository database operation
@ RestController to develop rest api
ResponseBody
The @ responseBody function is to convert the object returned by the controller method to the specified format through an appropriate converter, and then write it to the body area of the response object, which is usually used to return JSON data or XML.
Http://localhost:8080/responsebody
@ ResponseBody @ RequestMapping ("/ responseBody") public String responseBody () {return "hello springmvc";} RequestParam
Pass the parameter with the specified name in the request to the parameter assignment in the controller
Attributes:
Value: the name in the request parameter
Required: whether this parameter must be provided in the request parameters. The default value is true, and must be provided.
Http://localhost:8080/param?id=111
@ ResponseBody @ RequestMapping ("/ param") public String requestParam (@ RequestParam (value = "id", required = false) String userId) {return "hello" + userId;} RequestBody
Get the content of the request parameter. Because the get method has no body, all get cannot be used.
Attribute required: whether there must be a request body. The default is true.
@ ResponseBody @ RequestMapping (value = "/ requestBody", method = RequestMethod.POST) public String requestBody (@ RequestBody String body) {return body;}
Curl Test request Post
PathVariable
That owns a placeholder in the binding url. / delete/ {id}, {id} is a placeholder
Attribute value: specifies the placeholder name in url
RequestHeader
Gets the value of the specified request header
Attribute value: name of the request header
CookieValue
Gets the value of the name of the specified cookie
The name of the property value:cookie
ModelAttribute
Appears on the method: indicates that the current method will be executed on the front line of the controller method execution.
Appears on the parameter: gets the specified data to assign to the parameter.
Application scenarios:
1 when the submitted form data is not complete physical data, make sure that the unsubmitted fields use the original data of the database.
2 the modified method does not return a value
SessionAttributes
Parameter sharing among multiple execution controller methods
Attribute 1. Value: specifies the name of the stored attribute
At this point, I believe that you have a deeper understanding of the "Spring comments declaration bean", might as well come to the actual operation! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.