Her*_*iaz 5 java spring angularjs
我正在尝试使用Spring-boot和Angular 1.5实现HTML5路由,遵循本文.
在某些时候,我需要使用这样的控制器将所有角度路径重定向到基本路径:
@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:/";
}
}
Run Code Online (Sandbox Code Playgroud)
正则表达式匹配大多数URL,如仪表板,搜索等:
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]
Run Code Online (Sandbox Code Playgroud)
其他人被忽略,根本不匹配,例如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]
Run Code Online (Sandbox Code Playgroud)
如果你在regexplanet中测试它,正则表达式似乎没问题 ,但是如果我把它放在@RequestMapping中,它就不符合我想要的.有没有人知道如何使它工作,甚至更好的方法如何没有正则表达式?
| 归档时间: |
|
| 查看次数: |
1154 次 |
| 最近记录: |