使用了RestFul风格
//RestFul:http://localhost:8080/mvc/add/a/b
@RequestMapping("/add/{a}/{b}")
public String text01(@PathVariable int a, @PathVariable int b, Model model) {
int res = a + b;
model.addAttribute("msg","结果是:"+res);
return "addPage";
}
没有使用RestFul
//原来的:http://localhost:8080/mvc/add?a=1&b=2
@RequestMapping("/add")
public String text01(int a, int b, Model model) {
int res = a + b;
model.addAttribute("msg","结果是:"+res);
return "addPage";
}
使用指定的方式 地址请求栏默认都是HTTP GET
// @RequestMapping(value = "/add/{a}/{name}",method = RequestMethod.GET)
@PostMapping("/add/{a}/{name}")
public String text01(@PathVariable int a, @PathVariable String name, Model model) {
String res = name +a;
model.addAttribute("msg","结果1是:"+res);
return "addPage";
}
-
简洁:风格简单
-
安全:隐藏了程序里面的一些东西,比如参数等
-
高效:支持缓存