一、@RequestMapping("/user")
:请求映射路径的解析:
-
总结:一个"公共"的请求路径"前缀"
1.1代码块解析:
有@RequestMapping("/user")和@RequestMapping("/save")/ @RequestMapping("/delete")
@Controller
@RequestMapping("/user")
public class UserController {
@RequestMapping("/save")
@ResponseBody
public String save(){
System.out.println("User Save...");
return "{User Save...}";
}
@RequestMapping("/delete")
@ResponseBody
public String delete(){
System.out.println("User Delete...");
return "{User Delete...}";
}
所以在地址搜索:
二、请求参数
2.1 _"普通参数"的Get和Post方法(‘请求参数名’和‘代码的形参相同’)
*Get
*Post
2.2_"普通参数"的Get和Post方法(‘请求参数名’和‘代码的形参"不"相同’的情况)
解决:加一个@RequestParam("name")
的注解
2.3_POJO参数
User的代码块
public class User {
private String name;
private int age;
@Override
public String toString() {
return "User{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
public User(String name, int age) {
this.name = name;
this.age = age;
}
public User() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
2.4_嵌套POJO参数
这个和POJO就差在"传入的形参"
用PostMan测试"嵌套POJO"
输出结果
User代码块
public class User {
private String name;
private int age;
private Address address;
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public User(String name, int age) {
this.name = name;
this.age = age;
}
public User() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
内部嵌套Address的的代码块
public class Address {
private String province ;
private String city;
@Override
public String toString() {
return "Address{" +
"province='" + province + '\'' +
", city='" + city + '\'' +
'}';
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}
2.5_数组参数(必须要以代码"形参定义"为输入标准)
用PostMan测试:
测试结果:
2.5_集合参数
待更新.......
标签:return,String,springboot03,age,name,响应,User,public,请求 From: https://www.cnblogs.com/chen-zhou1027/p/16949225.html