easypoi-base-3.1.0一对多导出的bug

1,736 阅读1分钟

在做excel导出时,有类似如下的一对多的例子(官网例子):

public class CourseEntity {

    /** 课程名称 */
    @Excel(name = "课程名称", orderNum = "1", width = 25, needMerge = true)
    private String        name;

    /** 课程时长 */
    @Excel(name = "课程时长", orderNum = "2", width = 25, needMerge = true)
    private String        timelong;

    @ExcelCollection(name = "学生", orderNum = "2")
    private List<StudentEntity> students;

    @Excel(name = "备注", orderNum = "5", needMerge = true)
    private String memo;


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<StudentEntity> getStudents() {
        return students;
    }

    public void setStudents(List<StudentEntity> students) {
        this.students = students;
    }

    public String getMemo() {
        return memo;
    }

    public void setMemo(String memo) {
        this.memo = memo;
    }

    public String getTimelong() {
        return timelong;
    }

    public void setTimelong(String timelong) {
        this.timelong = timelong;
    }

public class StudentEntity {
    /**
     * id
     */
    private String        id;
    /**
     * 学生姓名
     */
    @Excel(name = "学生姓名", height = 20, width = 30, isImportField = "true_st")
    private String        name;
    /**
     * 学生性别
     */
    @Excel(name = "学生性别", replace = { "男_1", "女_2" }, suffix = "生", isImportField = "true_st")
    private int           sex;


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }

}

导出报IndexOutOfBoundsException错:

开始以为是@Excel注解哪里的问题,各种试,只有把ExcelCollection放到类的第二个属性时才可以,想要得到上面的效果始终不得解,后面根据错误打断点发现BaseExportService类存在一个bug(很低级):

百度搜easypoi-base的最新版本,更新到3.3.0测试,发现已解。OK!