瀏覽代碼

优化业务校验失败普通请求跳转页面

RuoYi 5 年之前
父節點
當前提交
d1b440fc0d

+ 0 - 2
ruoyi-admin/src/main/resources/templates/error/404.html

@@ -17,7 +17,5 @@
             <a href="javascript:top.document.location.href='/'" class="btn btn-primary m-t">主页</a>
         </div>
     </div>
-    <script src="/js/jquery.min.js?v=2.1.4"></script>
-    <script src="/js/bootstrap.min.js?v=3.3.6"></script>
 </body>
 </html>

+ 0 - 2
ruoyi-admin/src/main/resources/templates/error/500.html

@@ -18,7 +18,5 @@
             <a href="javascript:top.document.location.href='/'" class="btn btn-primary m-t">主页</a>
         </div>
     </div>
-    <script src="/js/jquery.min.js?v=2.1.4"></script>
-    <script src="/js/bootstrap.min.js?v=3.3.6"></script>
 </body>
 </html>

+ 20 - 0
ruoyi-admin/src/main/resources/templates/error/business.html

@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html lang="zh">
+<head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>RuoYi - 403</title>
+	<link href="/css/bootstrap.min.css" rel="stylesheet"/>
+    <link href="/css/animate.css" rel="stylesheet"/>
+    <link href="/css/style.css" rel="stylesheet"/>
+</head>
+<body class="gray-bg">
+    <div class="middle-box text-center animated fadeInDown">
+        <h3 class="font-bold">操作异常!</h3>
+
+        <div class="error-desc">
+            [[${errorMessage}]]
+        </div>
+    </div>
+</body>
+</html>

+ 0 - 2
ruoyi-admin/src/main/resources/templates/error/unauth.html

@@ -18,7 +18,5 @@
             <a href="javascript:top.document.location.href='/'" class="btn btn-outline btn-primary btn-xs">返回主页</a>
         </div>
     </div>
-    <script src="/js/jquery.min.js?v=2.1.4"></script>
-    <script src="/js/bootstrap.min.js?v=3.3.6"></script>
 </body>
 </html>

+ 13 - 2
ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java

@@ -77,10 +77,21 @@ public class GlobalExceptionHandler
      * 业务异常
      */
     @ExceptionHandler(BusinessException.class)
-    public AjaxResult businessException(BusinessException e)
+    public Object businessException(HttpServletRequest request, BusinessException e)
     {
         log.error(e.getMessage(), e);
-        return AjaxResult.error(e.getMessage());
+
+        if (ServletUtils.isAjaxRequest(request))
+        {
+            return AjaxResult.error(e.getMessage());
+        }
+        else
+        {
+            ModelAndView modelAndView = new ModelAndView();
+            modelAndView.addObject("errorMessage", e.getMessage());
+            modelAndView.setViewName("error/business");
+            return modelAndView;
+        }
     }
 
     /**