在统一处理数据时有些数据需要特殊化处理,这时就用到了类内部接口,在类中定义一个接口,并且定义这个接口的属性。
@Data
public class ExcelExportModel {
private ExcelExportModelValueFormat format;
/**
* 格式化数据
*/
public String valueFormat(String value) {
if (format != null) {
return format.valueFormat(value);
} else {
return value;
}
}
public ExcelExportModelValueFormat getFormat() {
return format;
}
public void setFormat(ExcelExportModelValueFormat format) {
this.format = format;
}
public interface ExcelExportModelValueFormat {
/**
* 格式化数据
*/
String valueFormat(String value);
}
}
创建数据处理函数:
ExcelExportModel custodianDate = new ExcelExportModel();
custodianDate.setFormat(value -> StringUtils.equals("永久", value) ? value : value + "天");
excelExportModelList.add(custodianDate);
使用:
String dictValue = DictUtils.getDictLabel(mode.getDicType(), valueObject.toString(), ",");
cell.setCellValue(mode.valueFormat(dictValue));