In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to solve the problem of using @ JsonFormat in spring boot projects. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Use @ JsonFormat to fail
Define the time format in the entity class
Reason: fastjson package is configured in the project
Fastjson package is also used to return data.
Return JSON.toJSONString (user)
After using jackson package for data conversion, the adjustment code displays normally.
ObjectMapper mapper = new ObjectMapper (); return mapper.writeValueAsString (user)
Effect picture:
Use @ JsonFormat to annotate the pit you stepped on
Project technology stack: Spring boot (2.1.6.RELEASE) + JDK (1.8) + Maven (apache-maven-3.5.4) + Mybatis-plus (3.4.0)
Recently, when working on a project system, the Java backend is required to return the time to the front-end page (local time-Beijing time), and the backend time field is mapped and converted according to Beijing time, no matter how it is handled. This is correct. But as long as it is displayed at the front end, it will be 8 hours less than Beijing time. After checking all the possible errors, I feel that there is nothing wrong with the code. But the front-end display is still 8 hours less, so there must be a problem. Look for it. My entity class is as follows: notice timezone = "GMT + 8" surrounded by a red box. We'll need it later.
Cause of error
This is also caused by one of my habits. There is a space on each side of the plus sign in the middle of the red box timezone = "GMT + 8", and then the time zone is not recognized when serialized. As a result, it is 8 hours less when it is transmitted to the front end for display, as shown in the following figure.
Solution
Once you know the cause of the problem, it's easy to change the problem, just delete the space in the middle. This is shown in the following figure.
Test it again. Got it.
Thank you for reading! This is the end of the article on "how to solve the problem of using @ JsonFormat in spring boot projects". 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, you can 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.