【Excel】导入报错Can not find 'Converter' support class LocalDateTime
爆错信息
什么意思呢:找不到"转换器"支持类LocalDateTime,就是导入的数据中有LocalDateTime类型的字段,Excel转换不支持LocalDateTime格式,需要写有一个LocalDateTime的转换类;
写转换类
java
public class LocalDateTimeConverter implements Converter<LocalDateTime> {
private static final String DEFAULT_PATTERN="yyyy-MM-dd HH:mm:ss";
@Override
public Class<LocalDateTime> supportJavaTypeKey() {
return LocalDateTime.class;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.STRING;
}
@Override
public LocalDateTime convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
return LocalDateTime.parse(cellData.getStringValue(), DateTimeFormatter.ofPattern(DEFAULT_PATTERN));
}
@Override
public CellData convertToExcelData(LocalDateTime value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
return new CellData<>(value.format(DateTimeFormatter.ofPattern(DEFAULT_PATTERN)));
}
}