janatar
janatar

Reputation: 123

Spring Mvc Dynamic RequestMapping

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

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

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

    ????     
    public void init()

}

How do I defined dynamic requestmapping?.

Upvotes: 3

Views: 8150

Answers (1)

nickdos
nickdos

Reputation: 8414

You could 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);
}

Upvotes: 8

Related Questions