javaEEday05-请求响应-请求-实体参数
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.inmind.controller;
|
||||
|
||||
import com.inmind.pojo.User;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@@ -21,7 +22,8 @@ public class RequestController {
|
||||
}*/
|
||||
|
||||
|
||||
//springboot方式获取请求参数
|
||||
//springboot方式获取请求参数(简单参数)
|
||||
|
||||
@RequestMapping( "/simpleParam")
|
||||
//@RequestParam(name = "name" ) 的作用是从请求对象中获取name属性值,将值赋给username变量
|
||||
public String simpleParam(@RequestParam(name = "name",required = false ) String username, Integer age){
|
||||
@@ -29,4 +31,13 @@ public class RequestController {
|
||||
return "OK";
|
||||
}
|
||||
|
||||
//实体参数
|
||||
@RequestMapping( "/simplePojo")
|
||||
public String simplePojo(User user){
|
||||
System.out.println(user);
|
||||
System.out.println("name:"+user.getName()+",age:"+user.getAge());
|
||||
System.out.println("address:"+user.getAddress());
|
||||
return "OK";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.inmind.pojo;
|
||||
|
||||
public class Address {
|
||||
private String province;
|
||||
private String city;
|
||||
|
||||
|
||||
public Address() {
|
||||
}
|
||||
|
||||
public Address(String province, String city) {
|
||||
this.province = province;
|
||||
this.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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Address{" +
|
||||
"province='" + province + '\'' +
|
||||
", city='" + city + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.inmind.pojo;
|
||||
|
||||
public class User {
|
||||
private String name;
|
||||
private Integer age;
|
||||
|
||||
private Address address;
|
||||
|
||||
public User() {
|
||||
}
|
||||
|
||||
public User(String name, Integer age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(Integer age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
"name='" + name + '\'' +
|
||||
", age=" + age +
|
||||
", address=" + address +
|
||||
'}';
|
||||
}
|
||||
|
||||
public Address getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(Address address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user