3

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

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

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

    ????     
    public void init()

}

如何定义动态请求映射?

4

1 回答 1

7

您也可以尝试以下方法:

@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);
}
于 2012-11-14T00:03:41.900 回答