Selaa lähdekoodia

加入了校验组 这个参数

4.1.3.A
jueyue 7 vuotta sitten
vanhempi
commit
cfb57c19d3
3 muutettua tiedostoa jossa 21 lisäystä ja 4 poistoa
  1. +12
    -0
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ImportParams.java
  2. +1
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/ExcelImportServer.java
  3. +8
    -3
      easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiValidationUtil.java

+ 12
- 0
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ImportParams.java Näytä tiedosto

@@ -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;
}
}

+ 1
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/ExcelImportServer.java Näytä tiedosto

@@ -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);


+ 8
- 3
easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiValidationUtil.java Näytä tiedosto

@@ -36,9 +36,14 @@ public class PoiValidationUtil {
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 null;


Ladataan…
Peruuta
Tallenna