您好老师请问这个注解请求问题
来源:2-1 SpringMVC开发REST风格Web程序
慕盖茨8087740
2019-07-27 09:46:48

请问老师这个注解和就业班最后一个项目 用的RequestMapping区别是啥 因为哪个注解不需要在后面加变量{"DEPT"}这种啊,url在前台随便几个变量都行,直接用参数HttpServletRequest获取的
1回答
芝芝兰兰
2019-07-27
同学你好。 @GetMapping是一个组合注解,等价于@RequestMapping(method = RequestMethod.GET),它将HTTP Get请求映射到特定的处理方法上。
1、比如,在视频中,使用@GetMapping("/emp/list/${DEPT}")代替了@RequestMapping(value ="/emp/list/${DEPT}",method = RequestMethod.GET),显然,这可以精简我们的代码。
2、再比如o2o中的LocalController可以改造为
@Controller
//@RequestMapping("/local")
public class LocalController {
@GetMapping("/local/{key}")
private String testLocal(@PathVariable("key") String key){
switch (key){
case "accountbind":
return "local/accountbind";
case "changepsw":
return "local/changepsw";
case "login":
return "local/login";
default:
return null;
}
}
// /**
// * 绑定帐号页路由
// *
// * @return
// */
// @RequestMapping(value = "/accountbind", method = RequestMethod.GET)
// private String accountbind() {
// return "local/accountbind";
// }
// /**
// * 修改密码页路由
// *
// * @return
// */
// @RequestMapping(value = "/changepsw", method = RequestMethod.GET)
// private String changepsw() {
// return "local/changepsw";
// }
// /**
// * 登录页路由
// *
// * @return
// */
// @RequestMapping(value = "/login", method = RequestMethod.GET)
// private String login() {
// return "local/login";
// }
}如果解答了同学的疑问,望采纳~
祝学习愉快~
相似问题