【Excel】- 导入报错Can not find ‘Converter‘ support class LocalDateTime

【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)));
	}
}
相关推荐
TPBoreas1 小时前
Jenkins 改完端口号启动不起来了
java·开发语言
金斗潼关1 小时前
SpringCloud GateWay网关
java·spring cloud·gateway
秋名RG2 小时前
深入解析建造者模式(Builder Pattern)——以Java实现复杂对象构建的艺术
java·开发语言·建造者模式
eternal__day2 小时前
Spring Boot 实现验证码生成与校验:从零开始构建安全登录系统
java·spring boot·后端·安全·java-ee·学习方法
陈大爷(有低保)3 小时前
swagger3融入springboot
java
海天胜景3 小时前
HTTP Error 500.31 - Failed to load ASP.NET Core runtime
后端·asp.net
海天胜景3 小时前
Asp.Net Core IIS发布后PUT、DELETE请求错误405
数据库·后端·asp.net
源码云商5 小时前
Spring Boot + Vue 实现在线视频教育平台
vue.js·spring boot·后端
weixin_376934635 小时前
JDK Version Manager (JVMS)
java·开发语言
月月大王5 小时前
easyexcel导出动态写入标题和数据
java·服务器·前端