实现Converter<T> 接口
重写下面几个方法:
public class SettlementConverter implements Converter<Integer> {
@Override
public Class supportJavaTypeKey() {
return null;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return null;
}
@Override
public Integer convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
return null;
}
@Override
public CellData convertToExcelData(Integer integer, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
return null;
}
}
在convertToExcelData()方法里面写将数据库字段转换成EXCEL显示字段的逻辑,如:
@Override
public CellData convertToExcelData(Integer integer, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
if(integer == 1){
return new CellData("男");
}else {
return new CellData("女");
}
}
然后在实体类上使用:
@ExcelProperty(value = "性别",converter = GenderConverter.class)