Spring Mvc Dynamic RequestMapping

My problem is the dynamic url on the controller. I have a category tree. My category has n subcategories.

My URL: www.xyz.com/category/mainCategory/subCategory/subCategory/subCategory/subCategory

@Controller @RequestMapping(value="/category/**") public class CategoryController { ???? public void init() } 

How to define dynamic query matching ?.

+4
source share
1 answer

You can also try something like:

 @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); } 
+8
source

Source: https://habr.com/ru/post/1445831/


All Articles