style: 代码扫描规范问题处理

This commit is contained in:
Chopper711 2023-06-05 10:05:40 +08:00
parent d9018ef317
commit b61a5e8f7b
2 changed files with 17 additions and 7 deletions

View File

@ -16,6 +16,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException; import javax.validation.ConstraintViolationException;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* 异常处理 * 异常处理
@ -112,7 +113,8 @@ public class GlobalControllerExceptionHandler {
// protected ResponseEntity<Object> handleExceptionInternal(Exception ex, Object body, HttpHeaders headers, HttpStatus status, WebRequest request) { // protected ResponseEntity<Object> handleExceptionInternal(Exception ex, Object body, HttpHeaders headers, HttpStatus status, WebRequest request) {
// if (ex instanceof MethodArgumentNotValidException) { // if (ex instanceof MethodArgumentNotValidException) {
// MethodArgumentNotValidException exception = (MethodArgumentNotValidException) ex; // MethodArgumentNotValidException exception = (MethodArgumentNotValidException) ex;
// return new ResponseEntity<>(new ResultUtil<>().setErrorMsg(exception.getBindingResult().getAllErrors().get(0).getDefaultMessage()), status); // return new ResponseEntity<>(new ResultUtil<>().setErrorMsg(exception.getBindingResult().getAllErrors().get(0).getDefaultMessage()),
// status);
// } // }
// if (ex instanceof MethodArgumentTypeMismatchException) { // if (ex instanceof MethodArgumentTypeMismatchException) {
// MethodArgumentTypeMismatchException exception = (MethodArgumentTypeMismatchException) ex; // MethodArgumentTypeMismatchException exception = (MethodArgumentTypeMismatchException) ex;
@ -138,10 +140,18 @@ public class GlobalControllerExceptionHandler {
BindException exception = (BindException) e; BindException exception = (BindException) e;
List<FieldError> fieldErrors = exception.getBindingResult().getFieldErrors(); List<FieldError> fieldErrors = exception.getBindingResult().getFieldErrors();
for (FieldError error : fieldErrors) { // 错误消息处理
return ResultUtil.error(ResultCode.PARAMS_ERROR.code(), error.getDefaultMessage()); try {
if (!fieldErrors.isEmpty()) {
return ResultUtil.error(ResultCode.PARAMS_ERROR.code(),
fieldErrors.stream()
.map(FieldError::getDefaultMessage) // 获取每个对象的名称字段
.collect(Collectors.joining(", ")));
} }
return ResultUtil.error(ResultCode.PARAMS_ERROR); return ResultUtil.error(ResultCode.PARAMS_ERROR);
} catch (Exception ex) {
return ResultUtil.error(ResultCode.PARAMS_ERROR);
}
} }
/** /**

View File

@ -223,7 +223,7 @@ public class AliPayPlugin implements Payment {
@Override @Override
public void callBack(HttpServletRequest request) { public void callBack(HttpServletRequest request) {
log.info("支付同步回调:"); log.info("支付同步回调:");
callback(request); checkPaymentResult(request);
} }
@ -274,9 +274,9 @@ public class AliPayPlugin implements Payment {
/** /**
* 验证支付结果 * 验证支付结果
* *
* @param request * @param request 请求
*/ */
private void callback(HttpServletRequest request) { private void checkPaymentResult(HttpServletRequest request) {
try { try {
AlipayPaymentSetting alipayPaymentSetting = alipayPaymentSetting(); AlipayPaymentSetting alipayPaymentSetting = alipayPaymentSetting();
//获取支付宝反馈信息 //获取支付宝反馈信息