SpringMVC REST 五大请求注解+ 三大入参注解 一、REST 请求注解全是 RequestMapping 衍生表格注解请求方式业务规范能否使用 RequestBodyGetMappingGET查询资源❌ 不支持PostMappingPOST新增资源✅ 支持PutMappingPUT全量更新资源✅ 支持DeleteMappingDELETE删除资源✅ 支持RequestMapping自定义 method通用接口根据请求方式决定1.GetMapping参数放在URL 地址栏/user?id1或/user/1幂等多次访问数据不变只查询不修改不能携带 json 请求体RequestBody注解失效//路径参数 GetMapping(/user/{id}) public Result findById(PathVariable Long id){} //url拼接参数 GetMapping(/list) public Result list(RequestParam String name){}2.PostMapping用于新增数据放在请求 Body (JSON)搭配RequestBody非幂等重复提交会重复创建数据PostMapping(/user) public Result add(RequestBody User user){}3.PutMapping全量修改必须带资源 id全字段覆盖更新幂等PutMapping(/user/{id}) public Result update(PathVariable Long id,RequestBody User user){}4.DeleteMapping根据 id 删除资源DeleteMapping(/user/{id}) public Result delete(PathVariable Long id){}补充前端不支持 PUT/DELETE 解决方案application.yml 开启隐式请求转换yamlspring: mvc: hiddenmethod: filter: enabled: true表单携带参数_methodput / _methoddelete二、三大入参注解核心区别1.PathVariable获取路径占位符参数地址/user/123GetMapping(/user/{uid}) public Result get(PathVariable(uid) Long id)来源URL 路径上适用REST 风格路径取值2.RequestParam获取 URL 拼接参数、表单参数地址/user?name张三age18GetMapping(/user) public Result get(RequestParam String name,Integer age)特点GET、POST 表单都能用RequestParam(required false)参数非必传3.RequestBody接收 Post/Put 请求中 Body 的 JSONPostMapping(/add) public Result save(RequestBody User user)只支持 POST/PUT/DELETEGET 不能使用前端请求头必须Content-Type:application/json自动把 JSON 字符串转为实体类