TIMESTAMP in MySQL datetime data type with T

TIMESTAMP in MySQL datetime data type with T

First, the scene description:

TIMESTAMP type using MySQL
entity class type used java.util.Date
return JSON data:
Here Insert Picture Description

Second, by annotation format (Method a)

Date type attribute may be on, or coupled with the GET method of Jackson @JsonFormat annotations formatted manner, for example:

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;

result:
Here Insert Picture Description

Second, through the global configuration (Method B)

@Configuration
public class WebMvcConfig {
    @Bean
    MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
        ObjectMapper mapper = new ObjectMapper();
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        converter.setObjectMapper(mapper);
        return converter;
    }
}

Published 348 original articles · won praise 1746 · Views 1.91 million +

Guess you like

Origin blog.csdn.net/qq_40147863/article/details/104344461