1 RestFull风格实例如下:
传统URL传参风格是http://localhost:8080/add?a=1&b=2, restfull风格通过@PathVariable修饰参数以达到路径类型传参。
2 前端访问的路径一样时,可以通过不同的请求方式予以区别
//RestFull风格是访问 http://localhost:8080/add/1/2
@RequestMapping(value = "/add/{a}/{b}",method = RequestMethod.GET)
public String demotest1(@PathVariable int a, @PathVariable int b, Model model){
int res = a + b;
model.addAttribute("msg","结果为:"+res);
return "test";
}
或者这样写:
// @PostMapping
// @PutMapping
// @DeleteMapping
@GetMapping(value = "/add/{a}/{b}")
public String demotest2(@PathVariable int a, @PathVariable int b, Model model){
int res = a + b;
model.addAttribute("msg","结果为:"+res);
return "test";
}
一些原生态的转发和重定向,可以欣赏一下:
注意:下图中的return中的页面如果是在WEB-INF中,前面需要加上/WEB-INF/