第十二节:学习Springboot接收请求参数(自学Spring boot 3.x的第三天)
大家好, 今天记录下如何使用Springboot接收请求参数。
第一种请求类型:通过post下的参数表单形式请求。
@PostMapping("/save")
public ResponseObject<Student> save(Student student){
return ResponseObject.createSuccessfulResp("请求成功",student);
}
第二种请求类型:通过post下的json形式请求。
记得在传入参数处添加@RequestBody注解
@PostMapping("/save/json")
public Student save1(@RequestBody Student student){
return student;
}
第三种,通过Get请求,自动封装到Student对象中
@GetMapping("/get")
public Student get(Student student){
return student;
}
第四种请求方式,通过@PathVariable注解实现路径传参
@GetMapping("get1/{age}")
public Student get1(@PathVariable Integer age){
Student student = new Student();
student.setAge(age);
return student;
}
第五种方法:通@RequestParam注解传参数
@GetMapping("/getParam")
public Student getParam(@RequestParam Integer age,@RequestParam String name){
Student student = new Student();
student.setName(name);
student.setAge(age);
return student;
}
原文地址:https://blog.csdn.net/qq_21004057/article/details/140597645
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!