// @PostMapping("/teststudent")
// public Student showStudent(String studentName, String studentAge){ //{"studentName":"hahaha","studentAge":"10"} 请求体这个,传递过来的都是null
// public Student showStudent(@RequestBody String studentName, String studentAge){ //这个只有studentname有值,而且把值都给了studentname{"studentName":"hahaha","studentAge":"10"}
// public Student showStudent(@RequestBody Student student){ // 请求体 {"studentName":"hahaha","studentAge":"10"} 这样可以
// public Student showStudent(@RequestParam("studentName") String studentName, @RequestParam("studentAge")String studentAge){ //{"studentName":"hahaha","studentAge":"10"} 这样也不行
// public Student showStudent(@RequestParam("studentName") String studentName, @RequestParam("studentAge")String studentAge){ //使用查询参数可以
// public Student showStudent(@PathParam("studentName") String studentName, @PathParam("studentAge")String studentAge){ //使用查询参数也可以
public Student showStudent(@PathParam("studentName") String studentName, @PathParam("studentAge")String studentAge){ //使用请求体也不行
Student student = new Student();
student.setStudentAge(studentAge);
student.setStudentName(studentName);
return student;
}
@GetMapping("/testgetstudent")
// public Student showGetStudent(@PathParam("studentName") String studentName, @PathParam("studentAge")String studentAge){ //{"studentName":"hahaha","studentAge":"10"} 这样不行
// public Student showGetStudent(@PathParam("studentName") String studentName, @PathParam("studentAge")String studentAge){ //使用查询参数可以
// public Student showGetStudent(Student student){ //使用查询参考可以
// public Student showGetStudent(Student student){ //{"studentName":"hahaha","studentAge":"10"} 这样不行
// public Student showGetStudent(@RequestParam("studentName") String studentName, @RequestParam("studentAge") String studentAge){ //{"studentName":"hahaha","studentAge":"10"} 这样不行
public Student showGetStudent(@RequestParam("studentName") String studentName, @RequestParam("studentAge") String studentAge){ // 查询参数 这样可以
Student student = new Student();
student.setStudentAge(studentAge);
student.setStudentName(studentName);
return student;
}
|