feat: 基础脚手架更新

This commit is contained in:
bootx
2025-03-02 00:27:06 +08:00
parent 52769e630a
commit 36a6901f8e
162 changed files with 1664 additions and 474 deletions

View File

@@ -18,6 +18,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.http.converter.HttpMessageConversionException;
import org.springframework.validation.BindException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@@ -86,6 +87,19 @@ public class RestExceptionHandler {
return Res.response(CommonErrorCode.VALIDATE_PARAMETERS_ERROR, message.toString(), MDC.get(CommonCode.TRACE_ID));
}
/**
* 请求参数校验未通过
*/
@ExceptionHandler({ MethodArgumentNotValidException.class })
public Result<Void> handleBusinessException(MethodArgumentNotValidException ex) {
log.info(ex.getMessage(), ex);
StringBuilder message = new StringBuilder();
for (var violation : ex.getAllErrors()) {
message.append(violation.getDefaultMessage()).append(System.lineSeparator());
}
return Res.response(CommonErrorCode.VALIDATE_PARAMETERS_ERROR, message.toString(), MDC.get(CommonCode.TRACE_ID));
}
/**
* 不支持 HTTP 请求方法异常
*/