Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that springboot configures date field to return timestamp

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "springboot configuration date field return timestamp problem how to solve", in the daily operation, I believe that many people in the springboot configuration date field return timestamp problem how to solve the problem, editor consulted all kinds of information, sorted out a simple and easy to use method of operation, hope to answer the "springboot configuration date field return timestamp problem how to solve" doubt! Next, please follow the editor to study!

When there is a problem, after springboot is upgraded to 2.0, the date checked out from the database is received by Date, and finally returned directly to the front end, which can be displayed normally in yyyy-MM-dd HH:mm:ss format in Google browser. But the date is "garbled" in IE browsers, because the springboot1.x version returns a timestamp in the Date field by default, while Google and IE automatically convert the timestamp to yyyy-MM-dd HH:mm:ss After springboot2.0, spring will automatically convert the Date field to UTC string (in the case of no configuration), so date needs to be converted to timestamp or yyyy-MM-dd HH:mm:ss. You need to add the following configuration in spring. I chose to return the timestamp configuration, which successfully solved the problem.

Configure return timestamp

Springjackson:serialization:write-dates-as-timestamps:true

The global configuration returns a string

Spring: jackson: date-format: yyyy-MM-dd HH:mm:ss time-zone: GMT+8

With the second configuration, there is no need to add @ JsonFormat (pattern = "yyyy-MM-dd HH:mm:ss", timezone= "GMT+8") to the date attribute of each entity class

# specify the execution environment spring: profiles: # active: @ env@ active: dev jackson: serialization: WRITE_DATES_AS_TIMESTAMPS: true. At this point, the study on "how to solve the problem of springboot configuring the timestamp returned by the date field" is over. I hope to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report