diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ImportParams.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ImportParams.java index fb63729..d08c489 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ImportParams.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ImportParams.java @@ -57,6 +57,10 @@ public class ImportParams extends ExcelBaseParams { * 是否需要保存上传的Excel,默认为false */ private boolean needSave = false; + /** + * 校验组 + */ + private Class[] verfiyGroup = null; /** * 是否需要校验上传的Excel,默认为false */ @@ -212,4 +216,12 @@ public class ImportParams extends ExcelBaseParams { public void setReadSingleCell(boolean readSingleCell) { this.readSingleCell = readSingleCell; } + + public Class[] getVerfiyGroup() { + return verfiyGroup; + } + + public void setVerfiyGroup(Class[] verfiyGroup) { + this.verfiyGroup = verfiyGroup; + } } diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/ExcelImportServer.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/ExcelImportServer.java index d7cc488..c0b5ea5 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/ExcelImportServer.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/ExcelImportServer.java @@ -262,7 +262,7 @@ public class ExcelImportServer extends ImportBaseService { boolean isAdd = true; Cell cell = null; if (params.isNeedVerfiy()) { - String errorMsg = PoiValidationUtil.validation(object); + String errorMsg = PoiValidationUtil.validation(object,params.getVerfiyGroup()); if (StringUtils.isNotEmpty(errorMsg)) { cell = row.createCell(row.getLastCellNum()); cell.setCellValue(errorMsg); diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiValidationUtil.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiValidationUtil.java index 1b77281..81d22e7 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiValidationUtil.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiValidationUtil.java @@ -36,9 +36,14 @@ public class PoiValidationUtil { validator = factory.getValidator(); } - public static String validation(Object obj) { - Set> set = validator.validate(obj); - if (set.size() > 0) { + public static String validation(Object obj, Class[] verfiyGroup) { + Set> set = null; + if(verfiyGroup != null){ + set = validator.validate(obj,verfiyGroup); + }else{ + set = validator.validate(obj); + } + if (set!= null && set.size() > 0) { return getValidateErrMsg(set); } return null;