【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)));
	}
}
相关推荐
华科易迅1 分钟前
Spring 事务(注解)
java·数据库·spring
写代码的小阿帆4 分钟前
Web工程结构解析:从MVC分层到DDD领域驱动
java·架构·mvc
千寻girling17 分钟前
不知道 Java 全栈 + AI 编程有没有搞头 ?
前端·人工智能·后端
小码哥_常23 分钟前
Spring Boot 实现网络限速:让流量“收放自如”
后端
东离与糖宝26 分钟前
Java 26+Spring Boot 3.5,微服务启动从3秒压到0.8秒
java·人工智能
禹中一只鱼1 小时前
【力扣热题100学习笔记】 - 哈希
java·学习·leetcode·哈希算法
凌波粒1 小时前
LeetCode--349.两个数组的交集(哈希表)
java·算法·leetcode·散列表
于先生吖1 小时前
Java+SpringBoot 无人健身房物联网系统完整源码实现
java·spring boot·物联网
johnrui1 小时前
SpringBoot-JdbcTemplate
java·spring boot·后端
码云社区1 小时前
JAVA二手车交易二手车市场系统源码支持微信小程序+微信公众号+H5+APP
java·开发语言·微信小程序·二手交易·闲置回收