Spring Mvc Dynamic RequestMapping

时间:2012-11-13 18:27:41

标签: java spring spring-mvc

我的问题是控制器上的动态网址。我有类别树。我的类别有n个子类别。

我的网址:www.xyz.com/category/mainCategory/subCategory/subCategory/subCategory/subCategory

@Controller
@RequestMapping(value="/category/**")
public class CategoryController {

    ????     
    public void init()

}

如何定义动态请求映射?。

1 个答案:

答案 0 :(得分:8)

您也可以尝试以下方式:

@RequestMapping(value="/category/{path}/**", method = RequestMethod.GET)
public void categoryTest(@PathVariable("path") String path, HttpServletRequest request) throws Exception {
    String remainingPaths = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    logger.debug("path = " + path + "/" + remainingPaths);
}