How do i get the requestmapping value in the controller?

后端 未结 5 2073
名媛妹妹
名媛妹妹 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:13

    Having a controller like

    @Controller
    @RequestMapping(value = "/web/objet")
    public class TestController {
    
        @RequestMapping(value = "/save")
        public String save(...) {
            ....
        }
    }
    

    You cant get the controller base requestMapping using reflection

    // Controller requestMapping
    String controllerMapping = this.getClass().getAnnotation(RequestMapping.class).value()[0];
    

    or the method requestMapping (from inside a method) with reflection too

    //Method requestMapping
    String methodMapping = new Object(){}.getClass().getEnclosingMethod().getAnnotation(RequestMapping.class).value()[0];
    

    Obviously works with an in requestMapping single value.

    Hope this helps.

提交回复
热议问题