When we use the @ResponseBody annotations in SPRINGMVC to return JSON data to the front end, we find that time is always a bunch of numbers, and here are two ways to solve time-format problems.
1. Use annotations on the Get method of the Time field
@JsonFormat (pattern = "Yyyy-mm-dd HH:mm:ss", timezone = "gmt+8")
The time that the frontend gets is the time format you set. But this method is a physical activity, you need to add this annotation to each time Type field.
2 to set the time format by configuring the JSON converter in the spring XML configuration file
@Component ("jacksonobjectmapper " ) The ref-pointing name in the configuration file corresponds to public class Customobjectmapper extends Objectmapper { private static final long serialversionuid = 1l; @PostConstruct public void afterpropertiesset () throws Exception {simpledateformat sdf = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"
XML file configuration for spring
<Mvc:annotation-driven> <mvc:message-converters> <Beans:beanclass= "Org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <Beans:propertyname= "Objectmapper"ref= "jacksonobjectmapper"/> < Propertyname= "Supportedmediatypes"> <List> <value>Application/json;charset=utf-8</value> </List> </ Property> </Beans:bean> </mvc:message-converters> </Mvc:annotation-driven>
Springmvc Unified settings return to the front-end JSON time format