In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to solve the pit of @ RequestBody with @ Data". 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 "how to solve the pit of @ RequestBody with @ Data".
@ RequestBody with @ Data's pit
If you use @ Data to modify an entity class, it's best not to use the same letters in succession, and never capitalize if you use it.
For example, the following User class
@ Datapublic class User {private Integer userId; private String tel; private String QQ;}
If you write like this, the QQ you get with @ RequestBody in the background method will become null
@ PostMapping (value = "/ addPrivGroup") public String addUser (@ RequestBody User user) {return userService.addUser (user);}
If you have to write QQ or qQ, either write getter and setter without @ Data, or add @ JsonProperty (value = "QQ") to the corresponding attribute.
The main reason is that when spring accepts parameters, it does not know whether the assignment method is setQQ or setqQ, which leads to the assignment of null.
@ requestbody,json,Date type conversion problem
@ requestbody receives the problem of mapping json parameters to Date (time and date) type conversion in entity classes
When app transmits Date type data, it has a time difference of 8 hours from that received in the background.
JsonFormat (pattern= "yyyy-MM-dd HH:mm:ss", timezone= "GMT+8") @ DateTimeFormat (pattern= "yyyy-MM-dd HH:mm:ss") private Date departureTime
Timezone mainly solves the "8 hours" problem.
Thank you for your reading. the above is the content of "how to solve @ RequestBody with @ Data". After the study of this article, I believe you have a deeper understanding of how to solve the problem of @ RequestBody with @ Data. The specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.