国际化定制

master
xuxueli 7 years ago
parent 7a362378a4
commit 820b4407d6
  1. 30
      xxl-job-admin/src/main/java/com/xxl/job/admin/controller/resolver/WebExceptionResolver.java
  2. 7
      xxl-job-admin/src/main/webapp/500.html
  3. 1
      xxl-job-admin/src/main/webapp/WEB-INF/template/common/common.result.ftl
  4. 2
      xxl-job-admin/src/main/webapp/WEB-INF/template/help.ftl

@ -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
@ -23,19 +24,34 @@ public class WebExceptionResolver implements HandlerExceptionResolver {
public ModelAndView resolveException(HttpServletRequest request, public ModelAndView resolveException(HttpServletRequest request,
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");
// error result
ReturnT<String> errorResult = new ReturnT<String>(ReturnT.FAIL_CODE, ex.toString().replaceAll("\n", "<br/>"));
// 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;
} else { } else {
mv.addObject("exceptionMsg", ex.toString().replaceAll("\n", "<br/>"));
mv.addObject("exceptionMsg", errorResult.getMsg());
mv.setViewName("/common/common.exception"); mv.setViewName("/common/common.exception");
return mv;
} }
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>

@ -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>&nbsp;&nbsp;&nbsp;&nbsp; <a target="_blank" href="https://github.com/xuxueli/xxl-job">Github</a>&nbsp;&nbsp;&nbsp;&nbsp;
<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…
Cancel
Save