@PathVariable
package com.test.demo;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class hello {
/**
*@author pxChen
*@date 2019/6/11 10:56
*/
@RequestMapping(value = "/test/{id}/{name}", method = RequestMethod.GET)
public String say(@PathVariable("id") Integer id, @PathVariable("name") String name) {
return "id:"+id+";name:"+name;
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/99eada23f8a930b5c2ea9fa24585201b.png)
@RequestParam
@RequestMapping(value = "/test", method = RequestMethod.GET)
public String msg(@RequestParam("name") String name, @RequestParam("msg") String msg) {
return name+" say: "+msg;
}
![](https://i-blog.csdnimg.cn/blog_migrate/eca239b4e56477069f029cd5a6c1f2e9.png)
@RequestBody(传递JSON数据)
@PostMapping("/show")
public String show(Person person) {
return "id:"+person.getId()+";name:"+person.getName();
}
![](https://i-blog.csdnimg.cn/blog_migrate/144bff313d928fd7056b0222ec576b06.png)
![](https://i-blog.csdnimg.cn/blog_migrate/f42dc667f859c6194304a85c94d52768.png)