From 673a9adc86b67986ada09b4ff44d4de9e51c9552 Mon Sep 17 00:00:00 2001 From: xuxin <840198532@qq.com> Date: Sat, 20 Sep 2025 16:41:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=B7=E6=B1=82-=E5=AE=9E=E4=BD=93=E5=8F=82?= =?UTF-8?q?=E6=95=B0&=E6=95=B0=E7=BB=84=E5=8F=82=E6=95=B0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inmind/controller/RequestController.java | 25 +++++++++ .../main/java/com/inmind/pojo/Address.java | 38 +++++++++++++ .../src/main/java/com/inmind/pojo/User.java | 55 +++++++++++++++++++ 3 files changed, 118 insertions(+) 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 15945ef..e8278f0 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,10 +1,12 @@ package com.inmind.controller; +import com.inmind.pojo.User; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; +import java.util.Arrays; @RestController//当前类是请求处理类 public class RequestController { @@ -30,4 +32,27 @@ public class RequestController { System.out.println(username +" "+ age); return "ok"; } + + + //接收实体参数 + @RequestMapping("/simplePojo") + public String simplePojo(User user){ + System.out.println(user); + return "ok"; + } + + //接收复杂实体参数 + @RequestMapping("/complexPojo") + public String complexPojo(User user){ + System.out.println(user); + return "ok"; + } + + //接收数组参数 + @RequestMapping("/arrayParam") + public String arrayParam(String[] hobby){ + System.out.println(hobby); + System.out.println(Arrays.toString(hobby)); + 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..68022a8 --- /dev/null +++ b/springboot-web-req-resp/src/main/java/com/inmind/pojo/Address.java @@ -0,0 +1,38 @@ +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..952f6da --- /dev/null +++ b/springboot-web-req-resp/src/main/java/com/inmind/pojo/User.java @@ -0,0 +1,55 @@ +package com.inmind.pojo; + +public class User { + private String name; + private Integer age; + private Address address; + + + public User(String name, Integer age, Address address) { + this.name = name; + this.age = age; + this.address = address; + } + + public Address getAddress() { + return address; + } + + public void setAddress(Address address) { + this.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 + + '}'; + } +}