How do i get the requestmapping value in the controller?

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

    For Spring 3.1 and above you can use ServletUriComponentsBuilder

    @RequestMapping("/search/")     
         public ResponseEntity searchWithSearchTerm(@RequestParam("name") String name) {  
             UriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentRequest();
             System.out.println(builder.buildAndExpand().getPath());
             return new ResponseEntity("OK", HttpStatus.OK);
         }
    

提交回复
热议问题