1.Get方式对参数的处理(@RequestParam)
/** * 描述: 演示接口和传参 * //@RestController 表示返回时JSON格式不是页面 */ @RestController public class ParaController { /** * //@RequestParam从请求中获取参数 */ @GetMapping("/para") public String requestPara(@RequestParam Integer num) { num = num + 1; return "我收到了参数:" + num; } }
1.1 测试
2.Post方式对参数的处理(@RequestBody)
/** * 描述: 演示接口和传参 * //@RestController 表示返回时JSON格式不是页面 */ @RestController public class ParaController { /** * postman:{"id":555,"name":"好学生"} 选择post Body raw下的json * */ @PostMapping("/post") public String postRequest(@RequestBody Student student) { return "我收到了post参数:" + student; } }
/** * 描述: 学生实体类 */ public class Student { Integer id; String name; @Override public String toString() { return "Student{" + "id=" + id + ", name='" + name + '\'' + '}'; } public Student(Integer id, String name) { this.id = id; this.name = name; } }
2.1 使用postman模拟请求
标签:RestController,name,URL,配置,id,num,004,public,String From: https://www.cnblogs.com/LLL0617/p/16860648.html