BeanMapUtils.create(oneRowData) 解析不匹配
建议先去看文档
com.alibaba.excel.exception.ExcelWriteDataConvertException: Can not find 'Converter' support class BankAccountUShieldStatusEnum. at com.alibaba.excel.write.executor.AbstractExcelWriteExecutor.doConvert(AbstractExcelWriteExecutor.java:323) at com.alibaba.excel.write.executor.AbstractExcelWriteExecutor.convert(AbstractExcelWriteExecutor.java:277) at com.alibaba.excel.write.executor.AbstractExcelWriteExecutor.converterAndSet(AbstractExcelWriteExecutor.java:58) at com.alibaba.excel.write.executor.ExcelWriteAddExecutor.addJavaObjectToExcel(ExcelWriteAddExecutor.java:174) at com.alibaba.excel.write.executor.ExcelWriteAddExecutor.addOneRowOfDataToExcel(ExcelWriteAddExecutor.java:82)
触发场景描述
BeanMapUtils.create(oneRowData) 构造的BeanMap无法与Field匹配导致ExcelContentProperty的属性为空,DTO字段名为"uShieldStatus",BeanMap中为"UShieldStatus"
触发Bug的代码
这里写代码
提示的异常或者没有达到的效果
大家尽量把问题一次性描述清楚,然后贴上全部异常,这样方便把问题一次性解决掉。 至少大家要符合一个原则就是,能让其他人复现出这个问题,如果无法复现,肯定无法解决。
easyExcel 一直都有这个问题, uShieldStatus 这样的驼峰式,在其他的一些JSON工具都有这个BUG, 一般字段不要这样起名,gNo, gName。 字段 改成 ushieldStatus , 或是 uuShieldStatus就没问题了
EasyExcel uses CGLIB to convert beans to map data types during write operations. CGLIB eventually calls the java.beans.Introspector#decapitalize method, which has its own parsing rules. This can cause properties like 'A' to be converted to 'a' through reflection, leading to data mismatches. You can either rename the property or convert it to lowercase to resolve the issue.I strongly recommend using standard camelCase for property names.
easyexcel在写入时,使用cglib将bean转换成map类型的数据。cglib最后调用的是java.beans.Introspector#decapitalize 方法。它有一套属于自己的解析规则,这导致类似'A'这种属性,反射的结果成为了'a',最终导致无法正常匹配数据写入。推荐使用正常的驼峰形式命名属性。
/**
* Utility method to take a string and convert it to normal Java variable
* name capitalization. This normally means converting the first
* character from upper case to lower case, but in the (unusual) special
* case when there is more than one character and both the first and
* second characters are upper case, we leave it alone.
* <p>
* Thus "FooBah" becomes "fooBah" and "X" becomes "x", but "URL" stays
* as "URL".
*
* @param name The string to be decapitalized.
* @return The decapitalized version of the string.
*/
public static String decapitalize(String name) {
if (name == null || name.length() == 0) {
return name;
}
if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) &&
Character.isUpperCase(name.charAt(0))){
return name;
}
char chars[] = name.toCharArray();
chars[0] = Character.toLowerCase(chars[0]);
return new String(chars);
}
It seems not a bug. I will remove BUG tag.
This issue has been completed, I will close this issue.