/**
* 全局异常处理:@ControllerAdvice + @ExceptionHandler 使用 GlobalExceptionHandler 全局处理 Controller 层异常的示例
*/
@ControllerAdvice
public class GlobalExceptionHandler {
// private static final Logger LOGGER = LoggerFactory.getLogger(GlobalExceptionHandler.class);
/**
* 处理入参时,参数校验异常
*
* @param e
* @return
*/
@ExceptionHandler(BindException.class)
@ResponseBody
public BaseResult handleException(BindException e) {
// LOGGER.error(e.getMessage(), e);
// 获取错误信息
String msg = e.getAllErrors().stream().map(ObjectError::getDefaultMessage).collect(Collectors.joining(","));
return BaseResult.result(false, msg);
}
}
全局处理hibernate-validator入参校验异常
最新推荐文章于 2024-05-07 13:56:25 发布