以两数加法为例展示。 项目结构如图所示: TestController
@RestController
public class TestController {
@RequestMapping("/test1/{a}&{b}")
public String test(@PathVariable("a") Integer a, @PathVariable("b") Integer b){
return a + b+"";
}
@RequestMapping(value = "/test2",params = {"a","b"})
public String test2(Integer a, Integer b){
return a + b+"";
}
@PostMapping(value = "/test3")
public String test3(@RequestBody Param param){
return param.getA()+param.getB()+"";
}
}
Param
public class Param {
private Integer a;
private Integer b;
public Integer getA() {
return a;
}
public void setA(Integer a) {
this.a = a;
}
public Integer getB() {
return b;
}
public void setB(Integer b) {
this.b = b;
}
}
|