MyBatis查询时间格式转换yyyy-MM-dd HH:mm:ss
一,通过配置model
model
private Date createTime;
@JsonFormat(pattern = "yyyy-MM-dd HH-mm-ss")
private Date updateTime;
加注解@JsonFormat(pattern = "yyyy-MM-dd HH-mm-ss")
比较麻烦
二,全局配置
@Configuration
public class DateConfig {
@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;
}
}
本文介绍两种在MyBatis中将日期格式统一为'yyyy-MM-dd HH:mm:ss'的方法:一种是在Model层使用注解@JsonFormat进行字段级别的格式设置;另一种是通过全局配置的方式,利用Spring Boot的Configuration类来实现。
1569

被折叠的 条评论
为什么被折叠?



