参数校验

This commit is contained in:
2025-04-30 10:18:18 +08:00
parent dc090de5ab
commit 99e002f054
12 changed files with 144 additions and 34 deletions

View File

@ -6,6 +6,7 @@ import com.greenorange.promotion.common.ResultUtils;
import io.swagger.v3.oas.annotations.Hidden;
import lombok.extern.slf4j.Slf4j;
import net.sf.jsqlparser.util.validation.ValidationError;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
@ -13,6 +14,7 @@ import org.springframework.validation.ObjectError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import java.util.ArrayList;
import java.util.Comparator;
@ -43,6 +45,13 @@ public class GlobalExceptionHandler {
}
// // 处理参数类型不匹配的异常
// @ExceptionHandler(MethodArgumentTypeMismatchException.class)
// public ResponseEntity<String> handleMethodArgumentTypeMismatch(MethodArgumentTypeMismatchException ex) {
// return ResponseEntity.badRequest().body("Invalid value for parameter: " + ex.getName());
// }
// 处理消息体解析失败的异常
@ExceptionHandler(HttpMessageNotReadableException.class)
public BaseResponse<?> handleHttpMessageNotReadableException(HttpMessageNotReadableException e) {