diff --git a/src/main/java/com/ruoyi/common/utils/DateUtils.java b/src/main/java/com/ruoyi/common/utils/DateUtils.java index 04c87d8..20dbbb7 100644 --- a/src/main/java/com/ruoyi/common/utils/DateUtils.java +++ b/src/main/java/com/ruoyi/common/utils/DateUtils.java @@ -147,7 +147,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils /** * 计算时间差 * - * @param endTime 最后时间 + * @param endDate 最后时间 * @param startTime 开始时间 * @return 时间差(天/小时/分钟) */ diff --git a/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java b/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java index 422ea94..5dd8bb1 100644 --- a/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java @@ -7,8 +7,10 @@ import org.springframework.security.access.AccessDeniedException; import org.springframework.validation.BindException; import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.MissingPathVariableException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; import com.ruoyi.common.constant.HttpStatus; import com.ruoyi.common.exception.DemoModeException; import com.ruoyi.common.exception.ServiceException; @@ -59,6 +61,28 @@ public class GlobalExceptionHandler return StringUtils.isNotNull(code) ? AjaxResult.error(code, e.getMessage()) : AjaxResult.error(e.getMessage()); } + /** + * 请求路径中缺少必需的路径变量 + */ + @ExceptionHandler(MissingPathVariableException.class) + public AjaxResult handleMissingPathVariableException(MissingPathVariableException e, HttpServletRequest request) + { + String requestURI = request.getRequestURI(); + log.error("请求路径中缺少必需的路径变量'{}',发生系统异常.", requestURI, e); + return AjaxResult.error(String.format("请求路径中缺少必需的路径变量[%s]", e.getVariableName())); + } + + /** + * 请求参数类型不匹配 + */ + @ExceptionHandler(MethodArgumentTypeMismatchException.class) + public AjaxResult handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e, HttpServletRequest request) + { + String requestURI = request.getRequestURI(); + log.error("请求参数类型不匹配'{}',发生系统异常.", requestURI, e); + return AjaxResult.error(String.format("请求参数类型不匹配,参数[%s]要求类型为:'%s',但输入值为:'%s'", e.getName(), e.getRequiredType().getName(), e.getValue())); + } + /** * 拦截未知的运行时异常 */ diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index ef000e2..9acb71f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -131,7 +131,7 @@ xss: urlPatterns: /system/*,/monitor/*,/tool/* # 代码生成 -gen: +gen: # 作者 author: ruoyi # 默认生成包路径 system 需改成自己的模块名称 如 system monitor tool