@RequestParam 和 @PathVariable以及@RequestBody 的区分
在 Spring MVC 开发中RequestParam和PathVariable是两种常用的参数绑定注解有时也会和RequestBody一起混用RequestParam取 URL 问号后面的查询参数。格式/api/user?userId123写法RequestParam(userId) Long userIdPathVariable取 URL路径中占位符的值。格式/api/user/123写法PathVariable(userId) Long userIdRequestBody取请求体里的 JSON通常用于 POST/PUT。格式{ userId: 123 }写法RequestBody UserDTO dto对比表注解数据来源典型 URL / 请求常用场景RequestParamURL ? 后面的参数/user?name张三搜索、过滤、分页PathVariableURL 路径中的占位符/user/123RESTful 查详情、删改RequestBody请求体 JSONPOST /user body新增、复杂对象提交