其实就是访问网络资源的格式
![](https://img-blog.csdnimg.cn/img_convert/7fc3e721357b04efd5408d967c3a64a1.png)
按照rest风格访问资源时使用行为动作区分对资源进行了何种操作
![](https://img-blog.csdnimg.cn/img_convert/a546b70a131ca05974f05105ab0d72a1.png)
这只是约定方式,不是强制要遵守的,可以打破,所以称为风格而不是规范,但为了更好地与他人合作应熟悉这种风格
描述模块的名称通常使用复数,表示此类资源,而非单个资源,比如users,books
根据rest风格对资源进行访问称为restful
在controller包下创建一个UserController
![](https://img-blog.csdnimg.cn/img_convert/2a866b8960fb23fc26e1ae505cbc5428.png)
代码如下:
![](https://img-blog.csdnimg.cn/img_convert/450a9434bfeceb90b2a3e5d4fdb56751.png)
带参数的情况
![](https://img-blog.csdnimg.cn/img_convert/e32eafa6c7d8d120cb4d401d2d7b3ed9.png)
用户postman进行请求发送:
![](https://img-blog.csdnimg.cn/img_convert/d1d89360c15b694ab8ac6b10f9598d0e.png)
查看idea控制台:
![](https://img-blog.csdnimg.cn/img_convert/fce0913d4edc791a37503557efbeb2b8.png)
总结:
![](https://img-blog.csdnimg.cn/img_convert/912043cb55ebe502c1982fd2472c4037.png)
![](https://img-blog.csdnimg.cn/img_convert/4487c5f64173c90a34978e6e951f6168.png)
![](https://img-blog.csdnimg.cn/img_convert/c396a390b32910abfd13a1413d9e0727.png)
![](https://img-blog.csdnimg.cn/img_convert/50f74fcd001a88540e9c930ca50c52dc.png)
Restful还可以简化
把映射路径写到这里,其他地方的value就可以删掉了
![](https://img-blog.csdnimg.cn/img_convert/815a076647f90ef3315e7ce233113a84.png)
但是如果带参数的话还得保留参数:
![](https://img-blog.csdnimg.cn/img_convert/170ccb0b6f27ff6540c46a9008408019.png)
@RequestBody也可以去掉,写到外面
![](https://img-blog.csdnimg.cn/img_convert/d8d4e02d9427512e977a570540d5358d.png)
@Controller和@ResponseBody还可以合并为@RestController
@RequestMapping(method = RequestMethod.POST)和@RequestMapping(value = "/{id}",method = RequestMethod.DELETE)还可以分别改为:@PostMapping和@PostMapping