Forráskód Böngészése

优化代码修改注释说明

hubin 1 éve
szülő
commit
a58f361168

+ 2 - 3
aizuda-service-parent/src/main/java/com/aizuda/service/service/IBaseService.java

@@ -12,7 +12,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import java.util.function.Supplier;
 
 /**
- * 爱组搭 http://aizuda.com
+ *  <a href="http://aizuda.com">爱组搭</a>
  * ----------------------------------------
  * 自定义 Service 基类
  *
@@ -41,14 +41,13 @@ public interface IBaseService<T> extends IService<T> {
      * @param message 存在提示
      */
     default void checkExists(LambdaQueryWrapper<T> lqw, String message) {
-        ApiAssert.nonEmpty(getOne(lqw.last("limit 1")), message);
+        ApiAssert.fail(count(lqw) > 0, message);
     }
 
     /**
      * 根据 ID 查询 检查数据合法性
      *
      * @param id 主键ID
-     * @return
      */
     default T checkById(Long id) {
         T t = this.getById(id);

+ 10 - 18
aizuda-service-parent/src/main/java/com/aizuda/service/web/ServiceExceptionHandler.java

@@ -9,6 +9,9 @@ import com.aizuda.common.toolkit.ThrowableUtils;
 import com.aizuda.core.api.ApiResult;
 import com.aizuda.core.api.IErrorCode;
 import com.aizuda.core.exception.ApiException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import jakarta.validation.ConstraintViolationException;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.HttpStatus;
@@ -23,9 +26,6 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
 import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
 import org.springframework.web.util.NestedServletException;
 
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-import jakarta.validation.ConstraintViolationException;
 import java.util.List;
 import java.util.Optional;
 import java.util.stream.Collectors;
@@ -51,7 +51,6 @@ public class ServiceExceptionHandler {
      *
      * @param request {@link HttpServletRequest}
      * @param e       {@link MethodArgumentNotValidException}
-     * @return
      */
     @ExceptionHandler({MethodArgumentNotValidException.class})
     @ResponseStatus(HttpStatus.OK)
@@ -65,7 +64,6 @@ public class ServiceExceptionHandler {
      *
      * @param request {@link HttpServletRequest}
      * @param e       {@link BindException}
-     * @return
      */
     @ExceptionHandler({BindException.class})
     @ResponseStatus(HttpStatus.OK)
@@ -78,9 +76,8 @@ public class ServiceExceptionHandler {
      * 验证异常处理 - @Validated加在 controller 类上,
      * 且在参数列表中直接指定constraints时触发
      *
-     * @param request
-     * @param ex
-     * @return
+     * @param request HttpServletRequest
+     * @param ex      ConstraintViolationException
      */
     @ExceptionHandler({ConstraintViolationException.class})
     @ResponseStatus(HttpStatus.OK)
@@ -92,8 +89,7 @@ public class ServiceExceptionHandler {
     /**
      * 转换FieldError列表为错误提示信息
      *
-     * @param fieldErrors
-     * @return
+     * @param fieldErrors List<FieldError>
      */
     private String convertFiledErrors(List<FieldError> fieldErrors) {
         return Optional.ofNullable(fieldErrors)
@@ -107,18 +103,15 @@ public class ServiceExceptionHandler {
     /**
      * 转换ConstraintViolationException 异常为错误提示信息
      *
-     * @param constraintViolationException
-     * @return
+     * @param constraintViolationException ConstraintViolationException
      */
     private String convertConstraintViolations(ConstraintViolationException constraintViolationException) {
         return Optional.ofNullable(constraintViolationException.getConstraintViolations())
                 .filter(constraintViolations -> this.enableValidationMessage)
                 .map(constraintViolations -> constraintViolations.stream().flatMap(constraintViolation -> {
                             String path = constraintViolation.getPropertyPath().toString();
-                            StringBuffer errorMessage = new StringBuffer();
-                            errorMessage.append(path.substring(path.lastIndexOf(".") + 1));
-                            errorMessage.append(" ").append(constraintViolation.getMessage());
-                            return Stream.of(errorMessage.toString());
+                            return Stream.of(path.substring(path.lastIndexOf(".") + 1) +
+                                    " " + constraintViolation.getMessage());
                         }).collect(Collectors.joining(", "))
                 ).orElse(null);
     }
@@ -128,7 +121,6 @@ public class ServiceExceptionHandler {
      *
      * @param e    异常类型
      * @param resp 响应请求
-     * @return
      */
     @ExceptionHandler(value = Throwable.class)
     public ApiResult<Object> handleBadRequest(Throwable e, HttpServletResponse resp) {
@@ -153,7 +145,7 @@ public class ServiceExceptionHandler {
             return ApiResult.failed(e.getMessage());
         }
 
-        /**
+        /*
          * 系统内部异常,打印异常栈
          */
         log.error("Error: handleBadRequest StackTrace : {}", ThrowableUtils.getStackTrace(e));