作者 RuoYi

优化代码

@@ -147,7 +147,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils @@ -147,7 +147,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
147 /** 147 /**
148 * 计算时间差 148 * 计算时间差
149 * 149 *
150 - * @param endTime 最后时间 150 + * @param endDate 最后时间
151 * @param startTime 开始时间 151 * @param startTime 开始时间
152 * @return 时间差(天/小时/分钟) 152 * @return 时间差(天/小时/分钟)
153 */ 153 */
@@ -7,8 +7,10 @@ import org.springframework.security.access.AccessDeniedException; @@ -7,8 +7,10 @@ import org.springframework.security.access.AccessDeniedException;
7 import org.springframework.validation.BindException; 7 import org.springframework.validation.BindException;
8 import org.springframework.web.HttpRequestMethodNotSupportedException; 8 import org.springframework.web.HttpRequestMethodNotSupportedException;
9 import org.springframework.web.bind.MethodArgumentNotValidException; 9 import org.springframework.web.bind.MethodArgumentNotValidException;
  10 +import org.springframework.web.bind.MissingPathVariableException;
10 import org.springframework.web.bind.annotation.ExceptionHandler; 11 import org.springframework.web.bind.annotation.ExceptionHandler;
11 import org.springframework.web.bind.annotation.RestControllerAdvice; 12 import org.springframework.web.bind.annotation.RestControllerAdvice;
  13 +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
12 import com.ruoyi.common.constant.HttpStatus; 14 import com.ruoyi.common.constant.HttpStatus;
13 import com.ruoyi.common.core.domain.AjaxResult; 15 import com.ruoyi.common.core.domain.AjaxResult;
14 import com.ruoyi.common.exception.DemoModeException; 16 import com.ruoyi.common.exception.DemoModeException;
@@ -60,6 +62,28 @@ public class GlobalExceptionHandler @@ -60,6 +62,28 @@ public class GlobalExceptionHandler
60 } 62 }
61 63
62 /** 64 /**
  65 + * 请求路径中缺少必需的路径变量
  66 + */
  67 + @ExceptionHandler(MissingPathVariableException.class)
  68 + public AjaxResult handleMissingPathVariableException(MissingPathVariableException e, HttpServletRequest request)
  69 + {
  70 + String requestURI = request.getRequestURI();
  71 + log.error("请求路径中缺少必需的路径变量'{}',发生系统异常.", requestURI, e);
  72 + return AjaxResult.error(String.format("请求路径中缺少必需的路径变量[%s]", e.getVariableName()));
  73 + }
  74 +
  75 + /**
  76 + * 请求参数类型不匹配
  77 + */
  78 + @ExceptionHandler(MethodArgumentTypeMismatchException.class)
  79 + public AjaxResult handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e, HttpServletRequest request)
  80 + {
  81 + String requestURI = request.getRequestURI();
  82 + log.error("请求参数类型不匹配'{}',发生系统异常.", requestURI, e);
  83 + return AjaxResult.error(String.format("请求参数类型不匹配,参数[%s]要求类型为:'%s',但输入值为:'%s'", e.getName(), e.getRequiredType().getName(), e.getValue()));
  84 + }
  85 +
  86 + /**
63 * 拦截未知的运行时异常 87 * 拦截未知的运行时异常
64 */ 88 */
65 @ExceptionHandler(RuntimeException.class) 89 @ExceptionHandler(RuntimeException.class)
@@ -112,7 +112,7 @@ module.exports = { @@ -112,7 +112,7 @@ module.exports = {
112 elementUI: { 112 elementUI: {
113 name: 'chunk-elementUI', // split elementUI into a single package 113 name: 'chunk-elementUI', // split elementUI into a single package
114 test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm 114 test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm
115 - priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app 115 + priority: 20 // the weight needs to be larger than libs and app or it will be packaged into libs or app
116 }, 116 },
117 commons: { 117 commons: {
118 name: 'chunk-commons', 118 name: 'chunk-commons',