标签:turn mode java ppi 方法 oca pat amp eth
@RequestMapping("/add")
public String test1(int a, int b, Model model) {
int res = a + b;
model.addAttribute("msg", "a + b = " + res);
return "test";
}
url: http://localhost:8080/r/add?a=5&b=2
页面输出:a + b = 7
@RequestMapping("/add/{a}/{b}")
public String test1(@PathVariable int a, @PathVariable int b, Model model) {
int res = a + b;
model.addAttribute("msg", "a + b = " + res);
return "test";
}
url:http://localhost:8080/r/add/5/2
页面输出:a + b = 7
//@RequestMapping(value = "/add/{a}/{b}", method = RequestMethod.GET)
@GetMapping("/add/{a}/{b}")//效果同上
public String test1(@PathVariable int a, @PathVariable String b, Model model) {
String res = a + b;
model.addAttribute("msg", "ab = " + res);
return "test";
}
@PostMapping("/add/{a}/{b}")//实现url复用
public String test2(@PathVariable int a, @PathVariable String b, Model model) {
String res = a + b;
model.addAttribute("msg", "ab = " + res);
return "test";
}
不同方法用不同的注释:
标签:turn mode java ppi 方法 oca pat amp eth
原文地址:https://www.cnblogs.com/pinked/p/12227373.html