How do i get the requestmapping value in the controller?

后端 未结 5 2075
名媛妹妹
名媛妹妹 2021-02-05 04:43

In the controller , i have this code, somehow, i want to get the request Mapping value \"search\". How is it possible ?

 @RequestMapping(\"/search/\")     
 publ         


        
5条回答
  •  日久生厌
    2021-02-05 05:12

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

提交回复
热议问题