Skip to content

导入异常自定义处理

清沐 edited this page Nov 12, 2019 · 3 revisions

导入时,可能因数据不符合要求导致导入错误,如对应属性为日期,但excel中内容值非日期。

调用exceptionally方法可自定义处理。

SaxExcelReader.of(CommonPeople.class).exceptionally((e, context) -> {
            System.out.println(context.getField().getName() + "_" + context.getVal() + "_" + context.getRowNum() + "_" + context.getColNum());
            return true;
}).read(path.toFile());

exceptionally方法返回true,则表示忽略该异常,继续导入,否则将终止导入

context上下文中包含当前被生成对象,字段,字段值,行号,列号,返回true时允许主动设值给被生成对象。

Clone this wiki locally