Spring Mvc Dynamic RequestMapping

jan*_*tar 4 java spring spring-mvc

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

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

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

    ????     
    public void init()

}
Run Code Online (Sandbox Code Playgroud)

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

nic*_*dos 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);
}
Run Code Online (Sandbox Code Playgroud)