2015-06-15 32 views
1

路徑有沒有辦法讓URL路徑的第一部分,前/ C:春RequestMapping:獲取用斜槓

完蛋了:/Category1/Subcategory1.1/Subcategory1.1.1/C/{categoryCode:*}

@Controller 
@RequestMapping(value = "/**/c") 
public class CategoryPageController { 

    @RequestMapping(value = "/{categoryCode:.*}", method = RequestMethod.GET) 
    public ModelAndView viewCategory(@PathVariable String categoryCode,    
      final HttpServletRequest request) { 
     String categoryPath = ... 

我試圖用AntPathMatcher(extractPathWithinPattern),但我不能確定正確的模式。

回答

0

inject the request object通過簡單地將HttpServletRequest添加到方法簽名,並通過調用getRequestURL()來添加 then access the Request Url

(OH和自動轉換的答案評論,計算器跳躍鯊魚)

+0

感謝快速回復。我噴射注入HttpServletRequest,但colling getRequestURL()我檢索完整路徑(http:// ....)我不需要它,我只需要「/ c /」之前的部分爲例:/ Category1 /Subcategory1.1/Subcategory1.1.1/ 關心 – scesnik