In the controller , i have this code, somehow, i want to get the request Mapping value "search". How is it possible ?
@RequestMapping("/search/") public Map searchWithSearchTerm(@RequestParam("name") String name) { // more code here }
If you want the pattern, you can try HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE
:
@RequestMapping({"/search/{subpath}/other", "/find/other/{subpath}"}) public Map searchWithSearchTerm(@PathVariable("subpath") String subpath, @RequestParam("name") String name) { String pattern = (String) request.getAttribute( HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); // pattern will be either "/search/{subpath}/other" or // "/find/other/{subpath}", depending on the url requested System.out.println("Pattern matched: "+pattern); }
It seems you are looking for the path that this request has matched, then you can directly get it from servlet path
@RequestMapping("/search/") public Map searchWithSearchTerm(@RequestParam("name") String name, HttpServletRequest request) { String path = request.getServletPath(); // more code here }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With