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

你想改變類的頂部或方法的頂部請求映射。我嘗試了所有可能的方式,但它不起作用。 –