mirror of https://gitee.com/stylefeng/roses
修改唯一字段校验值类型为Object
parent
d681346f48
commit
40779be3c4
|
@ -50,7 +50,7 @@ public class UniqueValidateParam {
|
||||||
/**
|
/**
|
||||||
* 被参数校验时候的字段的值
|
* 被参数校验时候的字段的值
|
||||||
*/
|
*/
|
||||||
String value;
|
Object value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验时,是否排除当前的记录
|
* 校验时,是否排除当前的记录
|
||||||
|
|
|
@ -42,7 +42,7 @@ import javax.validation.ConstraintValidatorContext;
|
||||||
* @author fengshuonan
|
* @author fengshuonan
|
||||||
* @date 2020/11/4 14:39
|
* @date 2020/11/4 14:39
|
||||||
*/
|
*/
|
||||||
public class TableUniqueValueValidator implements ConstraintValidator<TableUniqueValue, String> {
|
public class TableUniqueValueValidator implements ConstraintValidator<TableUniqueValue, Object> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 表名称,例如 sys_user
|
* 表名称,例如 sys_user
|
||||||
|
@ -89,7 +89,7 @@ public class TableUniqueValueValidator implements ConstraintValidator<TableUniqu
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid(String fieldValue, ConstraintValidatorContext context) {
|
public boolean isValid(Object fieldValue, ConstraintValidatorContext context) {
|
||||||
|
|
||||||
if (ObjectUtil.isNull(fieldValue)) {
|
if (ObjectUtil.isNull(fieldValue)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -120,7 +120,7 @@ public class TableUniqueValueValidator implements ConstraintValidator<TableUniqu
|
||||||
* @author fengshuonan
|
* @author fengshuonan
|
||||||
* @date 2020/8/17 21:55
|
* @date 2020/8/17 21:55
|
||||||
*/
|
*/
|
||||||
private UniqueValidateParam createAddParam(String fieldValue) {
|
private UniqueValidateParam createAddParam(Object fieldValue) {
|
||||||
return UniqueValidateParam.builder()
|
return UniqueValidateParam.builder()
|
||||||
.tableName(tableName)
|
.tableName(tableName)
|
||||||
.columnName(columnName)
|
.columnName(columnName)
|
||||||
|
@ -137,7 +137,7 @@ public class TableUniqueValueValidator implements ConstraintValidator<TableUniqu
|
||||||
* @author fengshuonan
|
* @author fengshuonan
|
||||||
* @date 2020/8/17 21:56
|
* @date 2020/8/17 21:56
|
||||||
*/
|
*/
|
||||||
private UniqueValidateParam createEditParam(String fieldValue) {
|
private UniqueValidateParam createEditParam(Object fieldValue) {
|
||||||
|
|
||||||
// 获取请求字段中id的值
|
// 获取请求字段中id的值
|
||||||
Dict requestParam = RequestParamContext.get();
|
Dict requestParam = RequestParamContext.get();
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
*/
|
*/
|
||||||
package cn.stylefeng.roses.kernel.validator.api.validators.unique.service;
|
package cn.stylefeng.roses.kernel.validator.api.validators.unique.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.stylefeng.roses.kernel.db.api.DbOperatorApi;
|
import cn.stylefeng.roses.kernel.db.api.DbOperatorApi;
|
||||||
import cn.stylefeng.roses.kernel.db.api.context.DbOperatorContext;
|
import cn.stylefeng.roses.kernel.db.api.context.DbOperatorContext;
|
||||||
|
@ -130,7 +131,7 @@ public class TableUniqueValueService {
|
||||||
if (StrUtil.isBlank(uniqueValidateParam.getColumnName())) {
|
if (StrUtil.isBlank(uniqueValidateParam.getColumnName())) {
|
||||||
throw new ParamValidateException(ValidatorExceptionEnum.TABLE_UNIQUE_VALIDATE_ERROR, "@TableUniqueValue注解上columnName属性为空");
|
throw new ParamValidateException(ValidatorExceptionEnum.TABLE_UNIQUE_VALIDATE_ERROR, "@TableUniqueValue注解上columnName属性为空");
|
||||||
}
|
}
|
||||||
if (StrUtil.isBlank(uniqueValidateParam.getValue())) {
|
if (ObjectUtil.isEmpty(uniqueValidateParam.getValue())) {
|
||||||
throw new ParamValidateException(ValidatorExceptionEnum.TABLE_UNIQUE_VALIDATE_ERROR, "@TableUniqueValue被校验属性的值为空");
|
throw new ParamValidateException(ValidatorExceptionEnum.TABLE_UNIQUE_VALIDATE_ERROR, "@TableUniqueValue被校验属性的值为空");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue