统一异常处理
This commit is contained in:
parent
8a3d930521
commit
18b8e4e396
|
@ -1,8 +0,0 @@
|
|||
package com.zheng.cms.admin.controller;
|
||||
|
||||
/**
|
||||
* Created by shuzheng on 2016/12/10.
|
||||
*/
|
||||
public class BaseController {
|
||||
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package com.zheng.cms.admin.controller;
|
||||
|
||||
import com.zheng.common.base.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.slf4j.Logger;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.zheng.cms.admin.controller.manage;
|
||||
|
||||
import com.zheng.cms.admin.controller.BaseController;
|
||||
import com.zheng.cms.dao.model.CmsArticle;
|
||||
import com.zheng.cms.dao.model.CmsArticleExample;
|
||||
import com.zheng.cms.rpc.api.CmsArticleService;
|
||||
import com.zheng.common.base.BaseController;
|
||||
import com.zheng.common.util.Paginator;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.zheng.cms.admin.controller.manage;
|
||||
|
||||
import com.zheng.cms.admin.controller.BaseController;
|
||||
import com.zheng.cms.dao.model.CmsCategory;
|
||||
import com.zheng.cms.dao.model.CmsCategoryExample;
|
||||
import com.zheng.cms.rpc.api.CmsCategoryService;
|
||||
import com.zheng.common.base.BaseController;
|
||||
import com.zheng.common.util.Paginator;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.zheng.cms.admin.controller.manage;
|
||||
|
||||
import com.zheng.cms.admin.controller.BaseController;
|
||||
import com.zheng.cms.dao.model.CmsComment;
|
||||
import com.zheng.cms.dao.model.CmsCommentExample;
|
||||
import com.zheng.cms.rpc.api.CmsCommentService;
|
||||
import com.zheng.common.base.BaseController;
|
||||
import com.zheng.common.util.Paginator;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.zheng.cms.admin.controller.manage;
|
||||
|
||||
import com.zheng.cms.admin.controller.BaseController;
|
||||
import com.zheng.cms.dao.model.CmsTag;
|
||||
import com.zheng.cms.dao.model.CmsTagExample;
|
||||
import com.zheng.cms.rpc.api.CmsTagService;
|
||||
import com.zheng.common.base.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.slf4j.Logger;
|
||||
|
|
|
@ -8,10 +8,18 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title><spring:message code="error"/></title>
|
||||
<meta charset="utf-8"/>
|
||||
<title><spring:message code="error"/></title>
|
||||
</head>
|
||||
<body>
|
||||
error
|
||||
<% Exception e = (Exception)request.getAttribute("ex"); %>
|
||||
<h2>错误: <%= e.getClass().getSimpleName()%></h2>
|
||||
<hr />
|
||||
<h5>错误描述:</h5>
|
||||
<%= e.getMessage()%>
|
||||
<h5>错误信息:</h5>
|
||||
<pre>
|
||||
<% e.printStackTrace(new java.io.PrintWriter(out)); %>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -8,10 +8,18 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title><spring:message code="error"/></title>
|
||||
<meta charset="utf-8"/>
|
||||
<title><spring:message code="error"/></title>
|
||||
</head>
|
||||
<body>
|
||||
error
|
||||
<% Exception e = (Exception)request.getAttribute("ex"); %>
|
||||
<h2>错误: <%= e.getClass().getSimpleName()%></h2>
|
||||
<hr />
|
||||
<h5>错误描述:</h5>
|
||||
<%= e.getMessage()%>
|
||||
<h5>错误信息:</h5>
|
||||
<pre>
|
||||
<% e.printStackTrace(new java.io.PrintWriter(out)); %>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,12 @@
|
|||
package com.zheng.cms.search.controller;
|
||||
|
||||
/**
|
||||
* 控制器基类
|
||||
* @author shuzheng
|
||||
* @date 2016年7月7日 上午10:08:47
|
||||
*/
|
||||
public class AppController {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package com.zheng.cms.search.controller;
|
||||
|
||||
/**
|
||||
* 控制器基类
|
||||
* @author shuzheng
|
||||
* @date 2016年7月7日 上午10:08:47
|
||||
*/
|
||||
public class BaseController {
|
||||
|
||||
public static final String RESULT = "result";
|
||||
public static final String DATA = "data";
|
||||
public static final String SUCCESS = "success";
|
||||
public static final String FAILED = "failed";
|
||||
|
||||
}
|
|
@ -8,10 +8,18 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title><spring:message code="error"/></title>
|
||||
<meta charset="utf-8"/>
|
||||
<title><spring:message code="error"/></title>
|
||||
</head>
|
||||
<body>
|
||||
error
|
||||
<% Exception e = (Exception)request.getAttribute("ex"); %>
|
||||
<h2>错误: <%= e.getClass().getSimpleName()%></h2>
|
||||
<hr />
|
||||
<h5>错误描述:</h5>
|
||||
<%= e.getMessage()%>
|
||||
<h5>错误信息:</h5>
|
||||
<pre>
|
||||
<% e.printStackTrace(new java.io.PrintWriter(out)); %>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -1,6 +1,7 @@
|
|||
package com.zheng.cms.web.controller;
|
||||
|
||||
import com.zheng.cms.dao.model.CmsUser;
|
||||
import com.zheng.common.base.BaseController;
|
||||
import com.zheng.common.util.JmsUtil;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
package com.zheng.cms.web.controller;
|
||||
|
||||
/**
|
||||
* 控制器基类
|
||||
* @author shuzheng
|
||||
* @date 2016年7月7日 上午10:08:47
|
||||
*/
|
||||
public class BaseController {
|
||||
|
||||
public static final String RESULT = "result";
|
||||
public static final String DATA = "data";
|
||||
public static final String SUCCESS = "success";
|
||||
public static final String FAILED = "failed";
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.zheng.cms.web.controller;
|
||||
|
||||
import com.zheng.cms.rpc.api.UserService;
|
||||
import com.zheng.common.base.BaseController;
|
||||
import com.zheng.common.util.EhCacheUtil;
|
||||
import com.zheng.common.util.PropertiesFileUtil;
|
||||
import net.sf.ehcache.Cache;
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.zheng.cms.web.controller;
|
|||
|
||||
import com.zheng.cms.dao.model.CmsUser;
|
||||
import com.zheng.cms.rpc.api.UserService;
|
||||
import com.zheng.common.base.BaseController;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
|
||||
import org.slf4j.Logger;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.zheng.cms.web.controller;
|
||||
|
||||
import com.zheng.common.base.BaseController;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.zheng.cms.web.controller;
|
||||
|
||||
import com.zheng.common.base.BaseController;
|
||||
import com.zheng.common.util.RedisUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.zheng.cms.web.controller;
|
|||
import com.zheng.cms.dao.model.CmsUser;
|
||||
import com.zheng.cms.dao.model.CmsUserExample;
|
||||
import com.zheng.cms.rpc.api.UserService;
|
||||
import com.zheng.common.base.BaseController;
|
||||
import com.zheng.common.util.Paginator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
|
@ -8,10 +8,18 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title><spring:message code="error"/></title>
|
||||
<meta charset="utf-8"/>
|
||||
<title><spring:message code="error"/></title>
|
||||
</head>
|
||||
<body>
|
||||
error
|
||||
<% Exception e = (Exception)request.getAttribute("ex"); %>
|
||||
<h2>错误: <%= e.getClass().getSimpleName()%></h2>
|
||||
<hr />
|
||||
<h5>错误描述:</h5>
|
||||
<%= e.getMessage()%>
|
||||
<h5>错误信息:</h5>
|
||||
<pre>
|
||||
<% e.printStackTrace(new java.io.PrintWriter(out)); %>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,36 @@
|
|||
package com.zheng.common.base;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* 控制器基类
|
||||
* Created by ZhangShuzheng on 2017/2/4.
|
||||
*/
|
||||
public abstract class BaseController {
|
||||
|
||||
private final static Logger _log = LoggerFactory.getLogger(BaseController.class);
|
||||
|
||||
public static final String RESULT = "result";
|
||||
public static final String DATA = "data";
|
||||
public static final String SUCCESS = "success";
|
||||
public static final String FAILED = "failed";
|
||||
|
||||
/**
|
||||
* 统一异常处理
|
||||
* @param request
|
||||
* @param response
|
||||
* @param exception
|
||||
*/
|
||||
@ExceptionHandler
|
||||
public String exceptionHandler(HttpServletRequest request, HttpServletResponse response, Exception exception) {
|
||||
_log.error("统一异常处理:", exception);
|
||||
request.setAttribute("ex", exception);
|
||||
return "/error";
|
||||
}
|
||||
|
||||
}
|
|
@ -8,10 +8,18 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title><spring:message code="error"/></title>
|
||||
<meta charset="utf-8"/>
|
||||
<title><spring:message code="error"/></title>
|
||||
</head>
|
||||
<body>
|
||||
error
|
||||
<% Exception e = (Exception)request.getAttribute("ex"); %>
|
||||
<h2>错误: <%= e.getClass().getSimpleName()%></h2>
|
||||
<hr />
|
||||
<h5>错误描述:</h5>
|
||||
<%= e.getMessage()%>
|
||||
<h5>错误信息:</h5>
|
||||
<pre>
|
||||
<% e.printStackTrace(new java.io.PrintWriter(out)); %>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,11 @@
|
|||
package com.zheng.pay.admin.controller;
|
||||
|
||||
/**
|
||||
* 控制器基类
|
||||
* @author shuzheng
|
||||
* @date 2016年7月7日 上午10:08:47
|
||||
*/
|
||||
public class AppController {
|
||||
|
||||
|
||||
}
|
|
@ -8,10 +8,18 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title><spring:message code="error"/></title>
|
||||
<meta charset="utf-8"/>
|
||||
<title><spring:message code="error"/></title>
|
||||
</head>
|
||||
<body>
|
||||
error
|
||||
<% Exception e = (Exception)request.getAttribute("ex"); %>
|
||||
<h2>错误: <%= e.getClass().getSimpleName()%></h2>
|
||||
<hr />
|
||||
<h5>错误描述:</h5>
|
||||
<%= e.getMessage()%>
|
||||
<h5>错误信息:</h5>
|
||||
<pre>
|
||||
<% e.printStackTrace(new java.io.PrintWriter(out)); %>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,8 @@
|
|||
package com.zheng.pay.web.controller;
|
||||
|
||||
|
||||
public class AppController {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -8,10 +8,18 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title><spring:message code="error"/></title>
|
||||
<meta charset="utf-8"/>
|
||||
<title><spring:message code="error"/></title>
|
||||
</head>
|
||||
<body>
|
||||
error
|
||||
<% Exception e = (Exception)request.getAttribute("ex"); %>
|
||||
<h2>错误: <%= e.getClass().getSimpleName()%></h2>
|
||||
<hr />
|
||||
<h5>错误描述:</h5>
|
||||
<%= e.getMessage()%>
|
||||
<h5>错误信息:</h5>
|
||||
<pre>
|
||||
<% e.printStackTrace(new java.io.PrintWriter(out)); %>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,7 @@
|
|||
package com.zheng.ucenter.home.controller;
|
||||
|
||||
public class AppController {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package com.zheng.ucenter.home.controller;
|
||||
|
||||
/**
|
||||
* 控制器基类
|
||||
* @author shuzheng
|
||||
* @date 2016年7月7日 上午10:08:47
|
||||
*/
|
||||
public class BaseController {
|
||||
|
||||
public static final String RESULT = "result";
|
||||
public static final String DATA = "data";
|
||||
public static final String SUCCESS = "success";
|
||||
public static final String FAILED = "failed";
|
||||
|
||||
}
|
|
@ -8,10 +8,18 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title><spring:message code="error"/></title>
|
||||
<meta charset="utf-8"/>
|
||||
<title><spring:message code="error"/></title>
|
||||
</head>
|
||||
<body>
|
||||
error
|
||||
<% Exception e = (Exception)request.getAttribute("ex"); %>
|
||||
<h2>错误: <%= e.getClass().getSimpleName()%></h2>
|
||||
<hr />
|
||||
<h5>错误描述:</h5>
|
||||
<%= e.getMessage()%>
|
||||
<h5>错误信息:</h5>
|
||||
<pre>
|
||||
<% e.printStackTrace(new java.io.PrintWriter(out)); %>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,28 @@
|
|||
package com.zheng.upms.admin.controller;
|
||||
|
||||
import com.zheng.common.base.BaseController;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/hello")
|
||||
public class HelloController extends BaseController {
|
||||
|
||||
@RequestMapping("/index")
|
||||
@ResponseBody
|
||||
public String index() {
|
||||
System.out.println(1/0);
|
||||
return "/hello/world";
|
||||
}
|
||||
|
||||
@RequestMapping("/index2")
|
||||
@ResponseBody
|
||||
public String index2() {
|
||||
String a = null;
|
||||
System.out.println(a.toString());
|
||||
return "/hello/world";
|
||||
}
|
||||
|
||||
}
|
|
@ -12,6 +12,14 @@
|
|||
<title><spring:message code="error"/></title>
|
||||
</head>
|
||||
<body>
|
||||
error
|
||||
<% Exception e = (Exception)request.getAttribute("ex"); %>
|
||||
<h2>错误: <%= e.getClass().getSimpleName()%></h2>
|
||||
<hr />
|
||||
<h5>错误描述:</h5>
|
||||
<%= e.getMessage()%>
|
||||
<h5>错误信息:</h5>
|
||||
<pre>
|
||||
<% e.printStackTrace(new java.io.PrintWriter(out)); %>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,8 @@
|
|||
package com.zheng.wechat.mp.admin.controller;
|
||||
|
||||
|
||||
public class AppController {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package com.zheng.wechat.mp.admin.controller;
|
||||
|
||||
/**
|
||||
* 控制器基类
|
||||
* @author shuzheng
|
||||
* @date 2016年7月7日 上午10:08:47
|
||||
*/
|
||||
public class BaseController {
|
||||
|
||||
public static final String RESULT = "result";
|
||||
public static final String DATA = "data";
|
||||
public static final String SUCCESS = "success";
|
||||
public static final String FAILED = "failed";
|
||||
|
||||
}
|
|
@ -8,10 +8,18 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title><spring:message code="error"/></title>
|
||||
<meta charset="utf-8"/>
|
||||
<title><spring:message code="error"/></title>
|
||||
</head>
|
||||
<body>
|
||||
error
|
||||
<% Exception e = (Exception)request.getAttribute("ex"); %>
|
||||
<h2>错误: <%= e.getClass().getSimpleName()%></h2>
|
||||
<hr />
|
||||
<h5>错误描述:</h5>
|
||||
<%= e.getMessage()%>
|
||||
<h5>错误信息:</h5>
|
||||
<pre>
|
||||
<% e.printStackTrace(new java.io.PrintWriter(out)); %>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue