springMvc-入參對象
阿新 • • 發佈:2017-06-17
ride map bsp clas inpu post pub 城市 進行
1.修改或者添加對象
2.多添件查詢時候也會遇到
springMvc能夠根據屬性自動的封裝pojo的對象並且支持關聯的對象:大致的原理是在傳入後臺的時候把前臺的屬性和對象封裝成json的形式傳入後臺,後臺根據傳入的對象,把Json的形式轉換為對象進行處理
具體使用:
-1.地址實體類:包含省份和城市倆個屬性
package com.atguigu.springmvc.entity; public class Adress { private String privence; private String city; public String getPrivence() {return privence; } public void setPrivence(String privence) { this.privence = privence; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } @Override public String toString() { return "Adress [privence=" + privence + ", city=" + city + ", getPrivence()=" + getPrivence() + ", getCity()=" + getCity() + ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()=" + super.toString() + "]"; } }
-2.創建用戶實體:包含用戶名,年齡和關聯對象地址
package com.atguigu.springmvc.entity;public class User { private String name; private String age; private Adress adress; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAge() { return age; } public void setAge(String age) { this.age = age; } public Adress getAdress() { return adress; } public void setAdress(Adress adress) { this.adress = adress; } @Override public String toString() { return "User [name=" + name + ", age=" + age + "]"; } }
-3.在頁面創建表單,包含用戶信息
<form action="springmvc/testPojo" method="post"> name:<input type="text" name="name" value=""/> age:<input type="text" name="age" value=""/> city:<input type="text" name="adress.city" value=""/> <input type="submit" value="提交PUT"/> </form>
-4.在controller中進行處理
@RequestMapping(value="/testPojo") public String testPojo(User user){ return SUCCESS; }
springMvc-入參對象