说我有这个:
@RequestMapping(value="/hello")
public ModelAndView hello(Model model){
System.out.println("HelloWorldAction.sayHello");
return null;
}
是否可以跳过value =“hello”部分,只需要@RequestMapping注释并让spring使用方法名作为值,类似于:
@RequestMapping
public ModelAndView hello(Model model){
System.out.println("HelloWorldAction.sayHello");
return null;
}
谢谢!
=================== EDIT =====================
试过这个但没有工作:
@Controller
@RequestMapping(value="admin", method=RequestMethod.GET)
public class AdminController {
@RequestMapping
public ResponseEntity<String> hello() {
System.out.println("hellooooooo");
}
}
答案 0 :(得分:4)
尝试在类
的请求映射值上添加“/ *”@Controller
@RequestMapping(value="admin/*")
public class AdminController {
@RequestMapping
public ResponseEntity<String> hello() {
System.out.println("hellooooooo");
}
}
答案 1 :(得分:3)
如果您根据特定方法移动RequestMethod,它应该有效:
@Controller
@RequestMapping(value="admin")
public class AdminController {
@RequestMapping(method=RequestMethod.GET)
public ResponseEntity<String> hello() {
System.out.println("hellooooooo");
}
}
访问它
祝你好运