| @@ -57,6 +57,10 @@ public class ImportParams extends ExcelBaseParams { | |||||
| * 是否需要保存上传的Excel,默认为false | * 是否需要保存上传的Excel,默认为false | ||||
| */ | */ | ||||
| private boolean needSave = false; | private boolean needSave = false; | ||||
| /** | |||||
| * 校验组 | |||||
| */ | |||||
| private Class[] verfiyGroup = null; | |||||
| /** | /** | ||||
| * 是否需要校验上传的Excel,默认为false | * 是否需要校验上传的Excel,默认为false | ||||
| */ | */ | ||||
| @@ -212,4 +216,12 @@ public class ImportParams extends ExcelBaseParams { | |||||
| public void setReadSingleCell(boolean readSingleCell) { | public void setReadSingleCell(boolean readSingleCell) { | ||||
| this.readSingleCell = readSingleCell; | this.readSingleCell = readSingleCell; | ||||
| } | } | ||||
| public Class[] getVerfiyGroup() { | |||||
| return verfiyGroup; | |||||
| } | |||||
| public void setVerfiyGroup(Class[] verfiyGroup) { | |||||
| this.verfiyGroup = verfiyGroup; | |||||
| } | |||||
| } | } | ||||
| @@ -262,7 +262,7 @@ public class ExcelImportServer extends ImportBaseService { | |||||
| boolean isAdd = true; | boolean isAdd = true; | ||||
| Cell cell = null; | Cell cell = null; | ||||
| if (params.isNeedVerfiy()) { | if (params.isNeedVerfiy()) { | ||||
| String errorMsg = PoiValidationUtil.validation(object); | |||||
| String errorMsg = PoiValidationUtil.validation(object,params.getVerfiyGroup()); | |||||
| if (StringUtils.isNotEmpty(errorMsg)) { | if (StringUtils.isNotEmpty(errorMsg)) { | ||||
| cell = row.createCell(row.getLastCellNum()); | cell = row.createCell(row.getLastCellNum()); | ||||
| cell.setCellValue(errorMsg); | cell.setCellValue(errorMsg); | ||||
| @@ -36,9 +36,14 @@ public class PoiValidationUtil { | |||||
| validator = factory.getValidator(); | validator = factory.getValidator(); | ||||
| } | } | ||||
| public static String validation(Object obj) { | |||||
| Set<ConstraintViolation<Object>> set = validator.validate(obj); | |||||
| if (set.size() > 0) { | |||||
| public static String validation(Object obj, Class[] verfiyGroup) { | |||||
| Set<ConstraintViolation<Object>> 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 getValidateErrMsg(set); | ||||
| } | } | ||||
| return null; | return null; | ||||