写一个类

public class LocalDateConverter implements Converter<LocalDateTime> {
@Override
public Class supportJavaTypeKey() {
return LocalDateTime.class;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return null;
}
@Override
public WriteCellData<?> convertToExcelData(LocalDateTime value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
LocalDate localDate = value.toLocalDate();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
return new WriteCellData<>(localDate.format(dateTimeFormatter));
}
}
在导出的实体类,有时分秒问题的属性上使用该类的反射

宽度调整

该类实现了Converter接口,用于将LocalDateTime对象转换为LocalDate,主要处理日期部分,格式化为yyyy-MM-dd。在导出实体类时,对于包含时分秒的属性,可以使用此类进行反射转换。
2542

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



