[alibaba/easyexcel]@ExcelIgnoreUnannotated 失效,所有字段都被生成了 excel 里的字段

2024-02-21 975 views
3
返回实体类

@Data
@EqualsAndHashCode(callSuper = true)
@ExcelIgnoreUnannotated
public final class DeviceAssetRespDTO extends BaseRespDTO {

    private Integer modelId;

    private Integer modelParentId;

    @ExcelProperty(value = "设备位置", index = 3)
    @ColumnWidth(15)
    private String modelParentName;

    private Integer supplierId;

    @ExcelProperty(value = "供应商", index = 5)
    @ColumnWidth(20)
    private String supplierName;

    private Integer deviceTypeId;

    @ExcelProperty(value = "设备类别", index = 2)
    @ColumnWidth(15)
    private String deviceTypeName;

    @ExcelProperty(value = "设备编码", index = 0)
    @ColumnWidth(15)
    private String code;

    @ExcelProperty(value = "设备名称", index = 1)
    @ColumnWidth(15)
    private String name;

    @ExcelProperty(value = "规格型号", index = 4)
    @ColumnWidth(15)
    private String spec;

    @ExcelProperty(value = "固定资产编号", index = 6)
    @ColumnWidth(20)
    private String assetNum;

    @ExcelProperty(value = "质保截止日期", index = 7)
    @ColumnWidth(20)
    private LocalDateTime expireTime;

    @ExcelProperty(value = "建档日期", index = 8)
    @ColumnWidth(20)
    private LocalDateTime archiveTime;

    @ExcelProperty(value = "设备状态", index = 9, converter = DeviceAssetExcelStateConverter.class)
    @ColumnWidth(15)
    private Integer state;

    private Integer runState;

    private Integer faultState;

    private Integer model;

    private Float speed;

    private Float current;

    private Float temperature;

    private String imgUrl;

    @ExcelProperty(value = "备注", index = 10)
    private String remark;

}
excel image

回答

0

我这边使用3.3.2版本用issue中的实体没有复现这个问题,你使用的easyexcel是什么版本 还有BaseRespDTO这个类和你导出的代码可以提供一下吗 方便复现

4

不好意思,是我返回的是 DeviceAssetRespDTO 对象,而我查出来的用的是 DeviceAssetRespDO,而我的 easyexcel 注解是用在 DeviceAssetRespDTO 类里的,所以没有生效,下面是我错误的代码

EasyExcelFactory
                .write(outputStream, DeviceAssetRespDTO.class)
                .sheet(fileName)
                .doWrite(getBaseMapper().listRecords(deviceAssetReqDTO.toQueryDO()));
2

错误使用了 api,不是 bug