[alibaba/easyexcel]javabean中的字段定义为枚举,导出时能实现自动转换吗

2024-05-11 186 views
0

public enum NoticeTypeEnum { //通知类型1:月结收费 2:欠费催缴 3:欠费断能 MONTH_SETTLE(1, "月结收费"), ARREARS_REMINDER(2, "欠费催缴"), ARREARS_OFF(3, "欠费断能"); @EnumValue private int code;

@JsonValue
private String desc;

NoticeTypeEnum(int code, String desc) {
    this.code = code;
    this.desc = desc;
}

public int getCode() {
    return code;
}

public void setCode(int code) {
    this.code = code;
}

}

@ColumnWidth(35) @ExcelProperty(value = "通知单类型",index = 2) @ApiModelProperty(value = "通知单类型", name = "noticeType") private NoticeTypeEnum noticeType;

实现导出时导出的是枚举的desc

回答

4

This can be done by manually implement a converter for enum type.

3

//新建一个getter @ColumnWidth(35) @ExcelProperty(value = "通知单类型",index = 2) public String getNoticeTypeDesc(){ return this.noticeType.getDesc(): };

4

@pineappleinairdrop
'@ExcelProperty' not applicable to method

1

@pineappleinairdrop '@ExcelProperty' not applicable to method

我的错 我是凭感觉说的 或许改成这样: @ColumnWidth(35) @ExcelProperty(value = "通知单类型",index = 2) private String noticeTypeDesc; public String getNoticeTypeDesc(){ return this.noticeType.getDesc(): }

2

使用自定义转换器