Skip to content

导入死循环bug #1364

Closed
Closed
@javaAjun

Description

@javaAjun
版本号:2.2
问题描述:

经测试,
jeecgController 类 第 101行 (如下图1) ImportParams setTitleRows=2
ExcelImportServer类 第250行 (如下图2)中的getTitleMap方法中 使用循环判断了起始行,该循环获取了ImportParams的titleRows作为headBegin变量的初始值.如果headRow为null就执行循环,循环结束后获取第headBegin行赋值给headRow,.如果excel文件的总行数小于3行,那么headRow初始值为2,sheet.getRow(headBegin++)永远为null,就会造成死循环.

建议修改方案:

建议判断文件内容起始行,读取每行第一个参数和反射中的类的每个字段的@Excel注解的name值做比对,如果比对上了,就基本可以认定为其实行.
最起码要判断一下文件总行数,ImportParams的titleRow肯定不能大于文件总行数,否则就死循环,如果文件总行数为0.就直接退出.

截图&代码:

image

image

友情提示: 未按格式要求发帖,会直接删掉。

Activity

tygithub1

tygithub1 commented on Jun 22, 2020

@tygithub1

添加代码:
int allRowNum = sheet.getPhysicalNumberOfRows(); for(headBegin = params.getTitleRows(); headRow == null && headBegin < allRowNum; headRow = sheet.getRow(headBegin++)) { } if(headRow==null){ throw new Exception("不识别该文件"); }
效果图:
image

javaAjun

javaAjun commented on Jun 22, 2020

@javaAjun
Author

添加代码:
int allRowNum = sheet.getPhysicalNumberOfRows(); for(headBegin = params.getTitleRows(); headRow == null && headBegin < allRowNum; headRow = sheet.getRow(headBegin++)) { } if(headRow==null){ throw new Exception("不识别该文件"); }
效果图:
image

这个逻辑对的,判断下总行数就不会死循环了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @zhangdaiscott@tygithub1@javaAjun

        Issue actions

          导入死循环bug · Issue #1364 · jeecgboot/JeecgBoot