1.在application.yml文件中添加:
spring.mvc.date-format:设置的格式
2.原理
- 1 在WebMvcAutoConfiguration文件中
@Bean
@Override
public FormattingConversionService mvcConversionService() {
WebConversionService conversionService = new WebConversionService(
this.mvcProperties.getDateFormat());
addFormatters(conversionService);
return conversionService;
}
- 2 其中
this.mvcProperties.getDateFormat()
表明取mvcProperties文件中的dateFormat
- 3 看mvcProperties知道在配置文件中spring.mvc前缀的dateFormat,默认格式dd/MM/yyy
@ConfigurationProperties(prefix = "spring.mvc")
public class WebMvcProperties {
/**
* Date format to use. For instance, `dd/MM/yyyy`.
*/
private String dateFormat;
网友评论