Excel支持dictType读取字符串组内容

This commit is contained in:
RuoYi
2020-06-23 21:05:38 +08:00
parent 9ad3cc0b9a
commit a3bb603382
2 changed files with 91 additions and 32 deletions

View File

@ -281,7 +281,7 @@ public class ExcelUtil<T>
}
else if (StringUtils.isNotEmpty(attr.dictType()))
{
val = reverseDictByExp(attr.dictType(), Convert.toStr(val));
val = reverseDictByExp(Convert.toStr(val), attr.dictType(), attr.separator());
}
ReflectUtils.invokeSetter(entity, propertyName, val);
}
@ -552,7 +552,7 @@ public class ExcelUtil<T>
}
else if (StringUtils.isNotEmpty(dictType))
{
cell.setCellValue(convertDictByExp(dictType, Convert.toStr(value)));
cell.setCellValue(convertDictByExp(Convert.toStr(value), dictType, separator));
}
else
{
@ -711,31 +711,33 @@ public class ExcelUtil<T>
/**
* 解析字典值
*
* @param dictType 字典类型
* @param dictValue 字典值
* @param dictType 字典类型
* @param separator 分隔符
* @return 字典标签
*/
public static String convertDictByExp(String dictType, String dictValue) throws Exception
public static String convertDictByExp(String dictValue, String dictType, String separator) throws Exception
{
Object bean = SpringUtils.getBean("dictUtils");
String methodName = "getDictLabel";
Method method = bean.getClass().getDeclaredMethod(methodName, String.class, String.class);
return Convert.toStr(method.invoke(bean, dictType, dictValue));
Method method = bean.getClass().getDeclaredMethod(methodName, String.class, String.class, String.class);
return Convert.toStr(method.invoke(bean, dictType, dictValue, separator));
}
/**
* 反向解析值字典值
*
* @param dictLabel 字典标签
* @param dictType 字典类型
* @param dictValue 字典标签
* @param separator 分隔符
* @return 字典值
*/
public static String reverseDictByExp(String dictType, String dictLabel) throws Exception
public static String reverseDictByExp(String dictLabel, String dictType, String separator) throws Exception
{
Object bean = SpringUtils.getBean("dictUtils");
String methodName = "getDictValue";
Method method = bean.getClass().getDeclaredMethod(methodName, String.class, String.class);
return Convert.toStr(method.invoke(bean, dictType, dictLabel));
Method method = bean.getClass().getDeclaredMethod(methodName, String.class, String.class, String.class);
return Convert.toStr(method.invoke(bean, dictType, dictLabel, separator));
}
/**