@GetMapping
@PostMapping
@PutMapping
@DeleteMapping
@PatchMapping
@GetMapping 是一个组合注解,平时使用的会比较多!
@Controller
public class RestFulController {
//原来的:http://localhost:8080/add?a=1&b=2
//RestFul:http://localhost:8080/add/1/2
// @RequestMapping(value ="/add/{a}/{b}",method = RequestMethod.POST)//功能与下相同
@PostMapping("/add/{a}/{b}")
public String test1(@PathVariable int a, @PathVariable String b, Model model){
String res = a + b;
model.addAttribute("msg","结果1POST为:"+res);
return "test";
}
@GetMapping("/add/{a}/{b}")
public String test2(@PathVariable int a, @PathVariable String b, Model model){
String res = a + b;
model.addAttribute("msg","结果2GET为:"+res);
return "test";
}
}
随便写一个a.jsp:
<body>
<form action="/add/1/5" method="post">
<input type="submit">
</form>
</body>
提交后如下图:
原文:https://www.cnblogs.com/xudong-he/p/15007646.html