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 spring use the method name as the value, similar to this:
@RequestMapping
public ModelAndView hello(Model model){
System.out.println("HelloWorldAction.sayHello");
return null;
}
Thanks!
===================EDIT=====================
Tried this but not working:
@Controller
@RequestMapping(value="admin", method=RequestMethod.GET)
public class AdminController {
@RequestMapping
public ResponseEntity<String> hello() {
System.out.println("hellooooooo");
}
}
The @RequestMapping annotation can be applied to class-level and/or method-level in a controller.
A Callable can be returned when the application wants to produce the return value asynchronously in a thread managed by Spring MVC. A DeferredResult can be returned when the application wants to produce the return value from a thread of its own choosing.
The @RequestParam annotation is used with @RequestMapping to bind a web request parameter to the parameter of the handler method.
RequestMapping annotation is used to map web requests onto specific handler classes and/or handler methods. @RequestMapping can be applied to the controller class as well as methods.
Try to add "/*" on the request mapping value of the class
@Controller
@RequestMapping(value="admin/*")
public class AdminController {
@RequestMapping
public ResponseEntity<String> hello() {
System.out.println("hellooooooo");
}
}
You can go the page http://localhost:8080/website/admin/hello
It should work if you move the RequestMethod on 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
Have a look here: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping
Good luck
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