spring boot 可以认为是spring mvc 的升级版。
在spring mvc 中,用的是@Controller注解
@RestController注解相当于 @Controller与@ResponseBody这两个注解的作用。
现在的web开发,大多数都是前后端分离的。所以用@RestController注解会更多。基本上不会用到ModelAndView了。
===========获取参数值================
@PathVariable(“”):获取url中restful风格的参数,适合于获取get请求的参数
@RequestMapping(value = "/say/{name}/{age}", method = RequestMethod.GET)
public String say(@PathVariable("name")String name,@PathVariable("age") int age){
return "hello " +name +" "+age;
}
@RequestParam(“”):获取传统请求中的参数(post或者get都可以),比如 http://localhost:8888/xxx/say123?name=zhangsan&age=19
@RequestMapping(value = "/say123", method = RequestMethod.GET)
public String say123(@RequestParam("name")String name,@RequestParam("age") int age){
return "hello " +name +" "+age;
}