In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail the notes on the use of @ RequestBody annotations in Springboot. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
@ RequestBody annotation trample @ RequestBody json injection Bean attribute is empty
1. When receiving JSON data and injecting it into Bean, you must add RuquestBody annotations.
2. Determine whether the attribute name field is the same
3. By default, spring does not assign values to JavaBean with uppercase initials. If you assign values with uppercase initials, you need to add @ JsonProperty (value= "AlarmTime") annotation.
Note: the first letter of the JavaBean specification attribute is lowercase, the hump is named: start with a lowercase letter, and the first letter of each word is uppercase.
4. The uppercase of the first letter cannot be assigned. Changing the Bean attribute to Public can also solve the problem (this solution is not recommended)
Example:
Try the specific operation in person.
Some notes for @ RequestBody annotations
1.@RequestBody annotations are used to obtain the data in the request body, which is directly used to get key=value&key=value. Structure, so get method is not applicable (@ RequestBody can't get any data in get mode).
Example:
Public void test1 (@ RequestBody String body) {system.out.println (body);}
Output result:
Username=hehe&age=20
two。 After using the @ RequestBody annotation, you can create a collection object in the method, and the collection data submitted by the front end can be injected directly into the method's collection object without creating a pojo object to encapsulate the collection.
3. If you want to automatically encapsulate the json string submitted by the front end into an object, you need to import the relevant jar package of jackson and use the @ RequestBody annotation.
Note: springmvc uses MappingJacksonHttpMessageConverter to convert json data by default.
4. The number of matches between the front and back end parameters of @ RequestBody cannot be reduced. The field name should be the same.
This is the end of this article on "precautions for the use of @ RequestBody annotations in Springboot". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.