Spring MVC @RequestMapping ... using method name as action value?

Say I have this:

@RequestMapping(value="/hello")
public ModelAndView hello(Model model){

    System.out.println("HelloWorldAction.sayHello");
    return null;      
}   

Is it possible to skip the value = "hello" part and just have the @RequestMapping annotation and have the spring method name as a value, similar to this:

@RequestMapping
public ModelAndView hello(Model model){

    System.out.println("HelloWorldAction.sayHello");
    return null;      
}

Thank!

==================== EDIT ======================

Tried this but didn't work:

@Controller
@RequestMapping(value="admin", method=RequestMethod.GET)
public class AdminController {

    @RequestMapping
    public ResponseEntity<String> hello() { 
      System.out.println("hellooooooo");
    }


}
+5
source share
2 answers

Try adding "/ *" to the class request match value

@Controller
@RequestMapping(value="admin/*")
public class AdminController {

    @RequestMapping
    public ResponseEntity<String> hello() { 
      System.out.println("hellooooooo");
    }
}

You can go to the page http: // localhost: 8080 / website / admin / hello

+4
source

It should work if you move RequestMethod according to your specific method:

@Controller
@RequestMapping(value="admin")
public class AdminController {

    @RequestMapping(method=RequestMethod.GET)
    public ResponseEntity<String> hello() { 
      System.out.println("hellooooooo");
    }
}

and access it through http: // hostname: port / admin / hello

: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping

.

+2

All Articles