对未包含 Validator 的 IConfig 实现类的处理
This commit is contained in:
@@ -21,6 +21,8 @@ import org.springframework.validation.Errors;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import jakarta.validation.UnexpectedTypeException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import quant.rich.emoney.controller.common.BaseController;
|
||||
import quant.rich.emoney.exception.PageNotFoundException;
|
||||
import quant.rich.emoney.interfaces.ConfigInfo;
|
||||
@@ -30,6 +32,7 @@ import quant.rich.emoney.service.ConfigService;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/admin/v1/config")
|
||||
@Slf4j
|
||||
public class ConfigControllerV1 extends BaseController {
|
||||
|
||||
@Autowired
|
||||
@@ -83,11 +86,17 @@ public class ConfigControllerV1 extends BaseController {
|
||||
MethodParameter methodParameter = new MethodParameter(method, 1);
|
||||
|
||||
// 执行校验
|
||||
BindingResult bindingResult = new BeanPropertyBindingResult(newConfig, clazz.getSimpleName());
|
||||
validator.validate(newConfig, bindingResult);
|
||||
try {
|
||||
BindingResult bindingResult = new BeanPropertyBindingResult(newConfig, clazz.getSimpleName());
|
||||
validator.validate(newConfig, bindingResult);
|
||||
|
||||
if (bindingResult.hasErrors()) {
|
||||
throw new MethodArgumentNotValidException(methodParameter, bindingResult);
|
||||
if (bindingResult.hasErrors()) {
|
||||
throw new MethodArgumentNotValidException(methodParameter, bindingResult);
|
||||
}
|
||||
}
|
||||
catch (UnexpectedTypeException e) {
|
||||
// 对指定类型未找到 validator,忽略之
|
||||
log.debug("Cannot find a validator for {}", clazz.getName());
|
||||
}
|
||||
|
||||
T oldConfig = configService.getConfig(clazz);
|
||||
|
||||
Reference in New Issue
Block a user