标签:接收 stat div end vax 基本数据类型 -- exce next
@RestControllerAdvice public class GlobalExceptionHandler { @ExceptionHandler(value=com.swimming.basic.exception.NotNullException.class) @ExceptionHandler(value=javax.validation.ConstraintViolationException.class) public R NotNullHandler(ConstraintViolationException e) { Set<ConstraintViolation<?>> violations = e.getConstraintViolations(); Iterator<ConstraintViolation<?>> iterator = violations.iterator(); StringBuffer message = new StringBuffer(""); while (iterator.hasNext()) { message.append(iterator.next().getMessage()); } return R.error().message(message.toString()); } //... }
Controller类
@GetMapping("findById") public R findById(@NotNull(message = "id不能为空") int id){ User user = userService.findById(id); return R.ok().data("user", user); }
此时如果请求时没有携带参数:id,不会产生ConstraintViolationException异常,而是:
标签:接收 stat div end vax 基本数据类型 -- exce next
原文地址:https://www.cnblogs.com/pikachu511/p/14890176.html