0

我想配置Spring将所有请求重定向到特定的控制器,而不考虑URL(长度和参数)。我应该如何在RequestMapping注释中提供URL模式/正则表达式。我尝试使用下面的代码,但它不工作。任何在这方面的帮助深表感谢。Spring REST请求映射

@Controller 
    @RequestMapping("/*") 
    public class ServiceController { 
     @RequestMapping(method = RequestMethod.GET, value = "*") 
     public void getProjectList(HttpServletRequest httpServletRequest,Model model){ 

     } 
    } 

回答

6

你需要@RequestMapping(method = RequestMethod.GET, value = "/**")

http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-patterns

除了URI模板中,@RequestMapping注释也 支持Ant风格路径图案(例如,/myPath/*.do)。

http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/util/AntPathMatcher.html

使用以下规则

映射匹配的URL:

  • ?匹配一个字符
  • *匹配的零个或多个字符
  • **匹配零或更多个目录在路径
+0

我们以前使用过上面的控制器映射,没有方法参数,维护服务器显示服务器当前正在维护中。有用... –

0

您是否试过使用正则表达式?

喜欢的东西:

@RequestMapping("/{value:.}") 
+0

你想改变类的顶部或方法的顶部请求映射。我尝试了所有可能的方式,但它不起作用。 –