spring short-code-sheet

2019-02-23  本文已影响0人  泠泉

HttpServletRequest request = 
  ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();

WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(request.getServletContext());
GroovyService groovyService = (GroovyService)webApplicationContext.getBean("GroovyService");

RequestCache requestCache = new HttpSessionRequestCache();
SavedRequest savedRequest = requestCache.getRequest(request, response);
String targetUrl = savedRequest.getRedirectUrl();

RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
redirectStrategy.sendRedirect(request, response, "登陆页的url");

NativeWebRequest webRequest = new ServletWebRequest(request);
Map<String, String> pathVariableMap = 
  (Map<String, String>) webRequest.getAttribute(
    HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, 
    RequestAttributes.SCOPE_REQUEST);
String id = pathVariableMap .get("id");  //get id pathvariable form request

StackTraceElement[] stacks = (new Throwable()).getStackTrace();
for (StackTraceElement stack : stacks) {
    System.out.println(stack.getClassName() + "-" + stack.getMethodName());
}
上一篇下一篇

猜你喜欢

热点阅读