[alibaba/easyexcel]字段有值, 但是输出数据为空

2024-05-24 158 views
2

触发场景描述

触发Bug的代码

 <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.7</version>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.18</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel</artifactId>
            <version>2.0.1</version>
        </dependency>
  @Test
    public void test111() throws IOException {
        String sss = "[{\"cActualMoney\":24,\"cShouldMoney\":24,\"category\":\"美妆个护/基础护肤/面膜\",\"childOrderId\":\"649035547506900992\",\"costPrice\":11.1,\"createTime\":1574783733000,\"gSinglePrice\":0,\"gTotalMoney\":0,\"orderId\":\"649035735168\",\"orderStatus\":\"待收货\",\"payWay\":\"支付宝\",\"postFee\":24,\"sendTime\":1574835662000,\"skuId\":\"100\",\"skuNum\":2,\"speci1\":\"5片/盒\",\"spid\":1,\"supplierName\":\"自营仓\",\"taxFee\":0,\"title\":\"保湿面膜5片/盒 修复屏障舒缓补水\"},{\"cActualMoney\":12,\"cShouldMoney\":12,\"category\":\"美氛/眼部彩妆\",\"childOrderId\":\"648675234324414464\",\"costPrice\":9.6,\"createTime\":1574697828000,\"gSinglePrice\":0,\"gTotalMoney\":0,\"orderId\":\"648675234303442944\",\"orderStatus\":\"待收货\",\"payWay\":\"微信\",\"postFee\":12,\"sendTime\":1574767548000,\"skuId\":\"10101\",\"skuNum\":1,\"speci1\":\"黑色\",\"spid\":200,\"supplierName\":\"石狮市有限公司\",\"taxFee\":0,\"title\":\"线笔 0.6ml*1支 不脱色持久不晕染 \"}]";
        List<ExcelOrderCommonVO> objects = JSON.parseArray(sss, ExcelOrderCommonVO.class);
        EasyExcel.write(new FileOutputStream(new File("D:/xxx.xlsx")), ExcelOrderCommonVO.class)
                .needHead(true)
                .sheet(0)
                .doWrite(objects);
    }
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 普通商品
 *
 * @author shuai-ys
 * @date 2019/11/26
 */
@Data
public class ExcelOrderCommonVO {

    @ExcelProperty(value = "父订单号", index = 0)
    private String orderId;

    @ExcelProperty(value = "子订单号", index = 1)
    private String childOrderId;

    @ExcelProperty(value = "下单时间", index = 2)
    private Date createTime;

    @ExcelProperty(value = "发货时间", index = 3)
    private Date sendTime;

    @ExcelProperty(value = "退货时间", index = 4)
    private Date backTime;

    @ExcelProperty(value = "供应商id", index = 5)
    private Integer spid;

    @ExcelProperty(value = "供应商名字", index = 6)
    private String supplierName;

    @ExcelProperty(value = "SkuId", index = 7)
    private String skuId;

    @ExcelProperty(value = "商品名称", index = 8)
    private String title;

    @ExcelProperty(value = "副标题", index = 9)
    private String subtitle;

    @ExcelProperty(value = "规格1", index = 10)
    private String speci1;

    @ExcelProperty(value = "规格2", index = 11)
    private String speci2;

    @ExcelProperty(value = "分类", index = 12)
    private String category;

    @ExcelProperty(value = "购买数量", index = 13)
    private Integer skuNum;

    @ExcelProperty(value = "退货数量", index = 14)
    private Integer returnNum;

    @ExcelProperty(value = "成本价", index = 15)
    private BigDecimal costPrice;

    @ExcelProperty(value = "商品单价", index = 16)
    private BigDecimal gSinglePrice;

    @ExcelProperty(value = "总售价(商品单价*数量)", index = 17)
    private BigDecimal gTotalMoney;

    @ExcelProperty(value = "(分摊)应付金额", index = 18)
    private BigDecimal cShouldMoney;

    @ExcelProperty(value = "(分摊)实付金额", index = 19)
    private BigDecimal cActualMoney;

    @ExcelProperty(value = "(分摊)优惠金额", index = 20)
    private BigDecimal cCouponMoney;

    @ExcelProperty(value = "(分摊)总返利", index = 21)
    private BigDecimal orderCommission;

    @ExcelProperty(value = "订单状态", index = 22)
    private String orderStatus;

    @ExcelProperty(value = "支付方式", index = 23)
    private String payWay;

    @ExcelProperty(value = "完成时间", index = 24)
    private Date confirmTime;

    @ExcelProperty(value = "邮费", index = 25)
    private BigDecimal postFee;

    @ExcelProperty(value = "税费", index = 26)
    private BigDecimal taxFee;

}

输出结果 image

回答

5

请遵循java命名规范,单个字母紧接着大写字母会让beanMap误以为是两个大写字母,导致找不到值

1

indeed

2

驼峰命名