From cfb57c19d3fbd26929769d3e6e5e61ef91f79812 Mon Sep 17 00:00:00 2001 From: jueyue Date: Mon, 18 Sep 2017 11:31:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E4=BA=86=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E7=BB=84=20=E8=BF=99=E4=B8=AA=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../afterturn/easypoi/excel/entity/ImportParams.java | 12 ++++++++++++ .../easypoi/excel/imports/ExcelImportServer.java | 2 +- .../cn/afterturn/easypoi/util/PoiValidationUtil.java | 11 ++++++++--- 3 files changed, 21 insertions(+), 4 deletions(-) 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;