From 83f6b32952d37093628b6471eb060d489199abc9 Mon Sep 17 00:00:00 2001 From: xuxin <840198532@qq.com> Date: Tue, 12 May 2026 15:06:54 +0800 Subject: [PATCH] =?UTF-8?q?javaEEday05-=E8=AF=B7=E6=B1=82=E5=93=8D?= =?UTF-8?q?=E5=BA=94-=E8=AF=B7=E6=B1=82-=E5=AE=9E=E4=BD=93=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inmind/controller/RequestController.java | 13 ++++- .../main/java/com/inmind/pojo/Address.java | 39 +++++++++++++++ .../src/main/java/com/inmind/pojo/User.java | 50 +++++++++++++++++++ 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 springboot-web-req-resp/src/main/java/com/inmind/pojo/Address.java create mode 100644 springboot-web-req-resp/src/main/java/com/inmind/pojo/User.java diff --git a/springboot-web-req-resp/src/main/java/com/inmind/controller/RequestController.java b/springboot-web-req-resp/src/main/java/com/inmind/controller/RequestController.java index 8eec2bd..8d7f3bf 100644 --- a/springboot-web-req-resp/src/main/java/com/inmind/controller/RequestController.java +++ b/springboot-web-req-resp/src/main/java/com/inmind/controller/RequestController.java @@ -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"; + } + } diff --git a/springboot-web-req-resp/src/main/java/com/inmind/pojo/Address.java b/springboot-web-req-resp/src/main/java/com/inmind/pojo/Address.java new file mode 100644 index 0000000..c30ed33 --- /dev/null +++ b/springboot-web-req-resp/src/main/java/com/inmind/pojo/Address.java @@ -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 + '\'' + + '}'; + } +} diff --git a/springboot-web-req-resp/src/main/java/com/inmind/pojo/User.java b/springboot-web-req-resp/src/main/java/com/inmind/pojo/User.java new file mode 100644 index 0000000..b720b1e --- /dev/null +++ b/springboot-web-req-resp/src/main/java/com/inmind/pojo/User.java @@ -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; + } + +}