请求-实体参数&数组参数获取
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
package com.inmind.controller;
|
package com.inmind.controller;
|
||||||
|
|
||||||
|
import com.inmind.pojo.User;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
@RestController//当前类是请求处理类
|
@RestController//当前类是请求处理类
|
||||||
public class RequestController {
|
public class RequestController {
|
||||||
@@ -30,4 +32,27 @@ public class RequestController {
|
|||||||
System.out.println(username +" "+ age);
|
System.out.println(username +" "+ age);
|
||||||
return "ok";
|
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";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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 + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
@@ -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 +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user