Spring Boot RESTful API
学习到接口部分了,记录一下
关于restful api感觉这篇文章讲的十分详细且通俗易懂一文搞懂什么是RESTful API - 知乎 (zhihu.com)
Spring Boot 提供的 spring-boot-starter-web 组件完全支持开发 RESTful API ,提供了
@GetMapping:处理get请求,获取资源
@PostMapping:处理post请求,新增资源
@PutMapping:处理put请求,更新资源
@DeleteMapping:处理delete请求,删除资源
@PatchMapping:处理patch请求,部分更新资源
@RestController
public class tempory {@GetMapping("/user/{id}")public String getUserById(@PathVariable int id) {return "get user by id";}@PostMapping("/user")public String save(User user) {return "add user";}@PutMappingpublic String update(User user) {return "update user";}@DeleteMapping("/user/{}id")public String deleteById(@PathVariable int id) {return "delete id by id";}}