@Configuration public class DateTimeFormatConfiguration extends WebMvcConfigurerAdapter { @Value(value = "${spring.jackson.date-format:yyyy-MM-dd HH:mm:ss}") private String formatString; @Override public void addFormatters(FormatterRegistry registry) { registry.addConverter(new DateConvert()); } public class DateConvert implements Converter<String, Date>{ private SimpleDateFormat formatter= new SimpleDateFormat(formatString); @Override public Date convert(String s) { if(StringUtil.isNullOrEmpty(s)){ return null; } try { Date date = formatter.parse(s); return date; } catch (ParseException e) { e.printStackTrace(); } return null; } } }
原文地址:https://www.cnblogs.com/Leechg/p/10362337.html
时间: 2024-10-07 19:38:00