当前位置:网站首页>来啦~ 使用 EasyExcel 导出时进行数据转换系列新篇章!
来啦~ 使用 EasyExcel 导出时进行数据转换系列新篇章!
2022-07-02 05:24:00 【泊船夜雪,他年可期】
来啦~ 使用 EasyExcel 导出时进行数据转换系列新篇章!
前情概要
之前使用 EasyExcel 进行数据导出功能的时候,类型转换处理(支付类型、男女、其他类型等)都是用的 if else 进行的判断处理,最近使用了Map 来进行处理,在这里记录一下。
代码实现
// 方式一
public class DemoTypeConverter implements Converter<String> {
public static final Map<String,String> DEMO_TYPE_MAP = ImmutableMap.<String,String>builder()
.put("类型1","01")
.put("类型2","02")
.put("类型3","03")
.put("类型4","04")
.put("类型5","05")
.put("类型6","06")
.put("类型7","07").build();
@Override
public Class supportJavaTypeKey() {
return String.class;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.STRING;
}
@Override
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
if (StringUtils.isBlank(cellData.getStringValue())){
return "";
}
return DEMO_TYPE_MAP.getOrDefault(cellData.getStringValue(),"");
}
@Override
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
return null;
}
}
// 方式二
public class DemoTypeConverter implements Converter<String> {
public static final Map<String,String> DEMO_TYPE_MAP = ImmutableMap.<String,String> of(
"类型1","01",
"类型2","02",
"类型3","03",
"类型4","04"
);
@Override
public Class supportJavaTypeKey() {
return String.class;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.STRING;
}
@Override
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
if (StringUtils.isBlank(cellData.getStringValue())){
return "";
}
return DEMO_TYPE_MAP.getOrDefault(cellData.getStringValue(),"");
}
@Override
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
return null;
}
}
总结
以上代码可以看出,两种方式的区别只是 Map 的构造方式不同,其他代码逻辑都一样。如果类型较多建议采用方式一,小于等于 4 种采用方式二。
边栏推荐
- Disable access to external entities in XML parsing
- Ls1046nfs mount file system
- 在线音乐播放器app
- Global and Chinese market of pressure gauges 2022-2028: Research Report on technology, participants, trends, market size and share
- 函数栈帧的创建和销毁
- 从数组中找出和为目标的下标
- Differential identities (help find mean, variance, and other moments)
- Foreign trade marketing website system development function case making
- Ubuntu 20.04 installing mysql8
- Fabric. JS three methods of changing pictures (including changing pictures in the group and caching)
猜你喜欢

brew install * 失败,解决方法

LS1046nfs挂载文件系统

Visual Studio导入

Using QA band and bit mask in Google Earth engine

Gee dataset: chirps pentad high resolution global grid rainfall dataset

Innovation never stops -- the innovation process of nvisual network visualization platform for Excel import

Operator details

Visual Studio導入

视差特效的原理和实现方法

"Original, excellent and vulgar" in operation and maintenance work
随机推荐
指针使用详解
Implementation of leetcode two number addition go
KMP idea and template code
Mysql基础---查询(1天学会mysql基础)
Find the subscript with and as the target from the array
Fabric.js IText 手动设置斜体
Installation du tutoriel MySQL 8.0.22 par centos8
go实现leetcode旋转数组
Visual Studio導入
7.1 simulation summary
Gee: remote sensing image composite and mosaic
黑馬筆記---Set系列集合
Gee series: unit 8 time series analysis in Google Earth engine [time series]
Global and Chinese market of travel data recorder (VDR) 2022-2028: Research Report on technology, participants, trends, market size and share
Fabric. JS background is not affected by viewport transformation
[opencv] image binarization
The reason why sizeof (ARR) / sizeof (arr[0]) is used in the function to calculate the length of the array is incorrect
Using QA band and bit mask in Google Earth engine
Fabric. JS upload local image to canvas background
Financial portal related information