目录
get请求
测试结果
基本数据类型与引用数据类型
自定义数据类型
json 数据类型
post 请求
测试结果
基本数据类型与引用数据类型
自定义数据类型
编辑 json 数据类型
put 请求
测试结果
基本数据类型和引用数据类型
自定义数据类型
json 数据类型
delete 请求
测试结果
基本数据类型与引用数据类型
自定义数据类型
编辑
json 数据类型
测试工具:idea + Postman
Student 类
@Data
public class Student {
public String username;
private Integer age;
}
get请求
package com.qfedu.springboot02.controller;
import com.qfedu.springboot02.enrity.Student;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class GetController {
@GetMapping("/")
public String show(String username, Integer age) {
return "username=" + username + " , age=" + age;
}
@GetMapping("/s")
public Student show01(Student student) {
return student;
}
@GetMapping("/sj")
public Student showJson(@RequestBody Student student) {
return student;
}
}
测试结果
基本数据类型与引用数据类型
基本数据类型与引用数据类型
自定义数据类型
json 数据类型
post 请求
package com.qfedu.springboot02.controller;
import com.qfedu.springboot02.enrity.Student;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class PostController {
@PostMapping("/")
public String add(String username, Integer age) {
return "username=" + username + " , age=" + age;
}
@PostMapping("/s")
public Student add01(Student student) {
return student;
}
@PostMapping("/sj")
public Student addJson(@RequestBody Student student) {
return student;
}
}
测试结果
基本数据类型与引用数据类型
自定义数据类型
json 数据类型
put 请求
package com.qfedu.springboot02.controller;
import com.qfedu.springboot02.enrity.Student;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class PutController {
@PutMapping("/")
public String update(String username, Integer age) {
return "username=" + username + " , age=" + age;
}
@PutMapping("/u")
public String update01(Student student) {
return "username=" + student.getUsername() + " , age=" + student.getAge();
}
@PutMapping("/up")
public String update02(@RequestBody Student student) {
return "username=" + student.getUsername() + " , age=" + student.getAge();
}
}
测试结果
基本数据类型和引用数据类型
自定义数据类型
json 数据类型delete 请求 测试结果 基本数据类型与引用数据类型
自定义数据类型json 数据类型
总结:get、post、put、delete 四种请求分别对应获取、添加、更新、删除数据,其实四种请求方式都一样,正常情况下用哪一种请求都没有区别。



