2016-08-05 87 views
4

我想实现HTML5路由弹簧引导和角1.5,跟随this articleHtml5路由与弹簧和角

在某些时候我需要所有的角路由到基座路径重定向与这样的控制器:

@Controller 
public class UrlController { 
    // Match everything without a suffix (so not a static resource) 
    @RequestMapping(value = "/{path:[^\\.]*}")) 
    public String redirect(HttpServletRequest request) { 
    // Forward to home page so that route is preserved. 
    return "forward:/"; 
    } 
} 

虽然正则表达式匹配大多数URLS的,如仪表盘,搜索等:

2016-08-05 16:39:58 DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping:306 - Looking up handler method for path /dashboard 
2016-08-05 16:39:58 DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping:313 - Returning handler method UrlController.redirect(javax.servlet.http.HttpServletRequest,java.lang.String)] 
2016-08-05 16:39:58 DEBUG o.s.b.f.s.DefaultListableBeanFactory:251 - Returning cached instance of singleton bean 'urlController' 
2016-08-05 16:39:58 DEBUG o.s.w.s.DispatcherServlet:947 - Last-Modified value for [/dashboard] is: -1 
2016-08-05 16:39:58 DEBUG c.a.a.w.i.LoggingInterceptor:22 - Start processing url request: https://localhost:8443/dashboard 
redirecting to home page from url https://localhost:8443/dashboard 
2016-08-05 16:39:58 DEBUG c.a.a.w.i.LoggingInterceptor:35 - Finished processing url request: https://localhost:8443/dashboard, duration: 0[ms] 

其他被忽略,且不匹配可言,就像https://localhost:8443/faults/64539352

2016-08-05 17:00:05 DEBUG o.s.w.s.DispatcherServlet:861 - DispatcherServlet with name 'dispatcherServlet' processing GET request for [/faults/64539352] 
2016-08-05 17:00:05 DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping:306 - Looking up handler method for path /faults/64539352 
2016-08-05 17:00:05 DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping:316 - Did not find handler method for [/faults/64539352] 

如果你在regexplanet 中测试它,那么正则表达式似乎没问题,但如果我把它放在@RequestMapping中,它就不符合我想要的。 有没有人知道如何使它工作,甚至更好的如何做到没有正则表达式?

+0

问题似乎是当您使用第二个“/”,服务器/东西是好的,但服务器/东西/任何东西在任何情况下都不匹配 –

回答

1

该问题和解决方案描述为here。该解决方案包含一个OncePerRequestFilter的实现,您可以在其中匹配完整的URI与任何你想要的。