国际化定制
This commit is contained in:
parent
7a362378a4
commit
820b4407d6
|
@ -11,6 +11,7 @@ import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* common exception resolver
|
* common exception resolver
|
||||||
|
@ -24,18 +25,33 @@ public class WebExceptionResolver implements HandlerExceptionResolver {
|
||||||
HttpServletResponse response, Object handler, Exception ex) {
|
HttpServletResponse response, Object handler, Exception ex) {
|
||||||
logger.error("WebExceptionResolver:{}", ex);
|
logger.error("WebExceptionResolver:{}", ex);
|
||||||
|
|
||||||
ModelAndView mv = new ModelAndView();
|
// if json
|
||||||
|
boolean isJson = false;
|
||||||
HandlerMethod method = (HandlerMethod)handler;
|
HandlerMethod method = (HandlerMethod)handler;
|
||||||
ResponseBody responseBody = method.getMethodAnnotation(ResponseBody.class);
|
ResponseBody responseBody = method.getMethodAnnotation(ResponseBody.class);
|
||||||
if (responseBody != null) {
|
if (responseBody != null) {
|
||||||
response.setContentType("application/json;charset=UTF-8");
|
isJson = true;
|
||||||
mv.addObject("result", JacksonUtil.writeValueAsString(new ReturnT<String>(500, ex.toString().replaceAll("\n", "<br/>"))));
|
}
|
||||||
mv.setViewName("/common/common.result");
|
|
||||||
} else {
|
// error result
|
||||||
mv.addObject("exceptionMsg", ex.toString().replaceAll("\n", "<br/>"));
|
ReturnT<String> errorResult = new ReturnT<String>(ReturnT.FAIL_CODE, ex.toString().replaceAll("\n", "<br/>"));
|
||||||
mv.setViewName("/common/common.exception");
|
|
||||||
|
// response
|
||||||
|
ModelAndView mv = new ModelAndView();
|
||||||
|
if (isJson) {
|
||||||
|
try {
|
||||||
|
response.setContentType("application/json;charset=utf-8");
|
||||||
|
response.getWriter().print(JacksonUtil.writeValueAsString(errorResult));
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
return mv;
|
return mv;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
mv.addObject("exceptionMsg", errorResult.getMsg());
|
||||||
|
mv.setViewName("/common/common.exception");
|
||||||
|
return mv;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>应用程序异常 (500)</title>
|
<title>Error</title>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
||||||
div.dialog {
|
div.dialog {
|
||||||
|
@ -21,8 +21,9 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div class="dialog">
|
<div class="dialog">
|
||||||
<h1>应用程序异常</h1>
|
<h1>System Error</h1>
|
||||||
<p>抱歉!您访问的页面出现异常,请稍后重试或联系管理员。</p>
|
<p>Oops! Page not found.</p>
|
||||||
|
<a href="javascript:window.location.href='${request.contextPath}/'">Back</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
${result?if_exists}
|
|
|
@ -25,7 +25,7 @@
|
||||||
<h4>${I18n.admin_name_full}</h4>
|
<h4>${I18n.admin_name_full}</h4>
|
||||||
<br>
|
<br>
|
||||||
<p>
|
<p>
|
||||||
<a target="_blank" href="https://github.com/xuxueli/xxl-job">github</a>
|
<a target="_blank" href="https://github.com/xuxueli/xxl-job">Github</a>
|
||||||
<iframe src="https://ghbtns.com/github-btn.html?user=xuxueli&repo=xxl-job&type=star&count=true" frameborder="0" scrolling="0" width="170px" height="20px" style="margin-bottom:-5px;"></iframe>
|
<iframe src="https://ghbtns.com/github-btn.html?user=xuxueli&repo=xxl-job&type=star&count=true" frameborder="0" scrolling="0" width="170px" height="20px" style="margin-bottom:-5px;"></iframe>
|
||||||
<br><br>
|
<br><br>
|
||||||
<a target="_blank" href="http://www.xuxueli.com/xxl-job/">${I18n.job_help_document}</a>
|
<a target="_blank" href="http://www.xuxueli.com/xxl-job/">${I18n.job_help_document}</a>
|
||||||
|
|
Loading…
Reference in New Issue