1.介绍
2.Person.java
1 package com.spring.bean; 2 3 public class Person { 4 private String username; 5 private String password; 6 private String email; 7 private int age; 8 private Address address; 9 10 public Person() {}11 public Person(String username, String password, String email, int agem,Address address) {12 super();13 this.username = username;14 this.password = password;15 this.email = email;16 this.age = age;17 this.address = address;18 }19 public String getUsername() {20 return username;21 }22 public void setUsername(String username) {23 this.username = username;24 }25 public String getPassword() {26 return password;27 }28 public void setPassword(String password) {29 this.password = password;30 }31 public String getEmail() {32 return email;33 }34 public void setEmail(String email) {35 this.email = email;36 }37 public int getAge() {38 return age;39 }40 public void setAge(int age) {41 this.age = age;42 }43 public Address getAddress() {44 return address;45 }46 public void setAddress(Address address) {47 this.address = address;48 }49 @Override50 public String toString() {51 return "Person [username=" + username + ", password=" + password + ", email=" + email + ", age=" + age52 + ", address=" + address + "]";53 }54 55 }
3.address.java
1 package com.spring.bean; 2 3 /** 4 * 为了验证级联属性做的bean 5 * @author dell 6 * 7 */ 8 public class Address { 9 private String province;10 private String city;11 public Address() {}12 public Address(String province, String city) {13 super();14 this.province = province;15 this.city = city;16 }17 public String getProvince() {18 return province;19 }20 public void setProvince(String province) {21 this.province = province;22 }23 public String getCity() {24 return city;25 }26 public void setCity(String city) {27 this.city = city;28 }29 @Override30 public String toString() {31 return "Address [province=" + province + ", city=" + city + "]";32 }33 34 }
4.controller
1 package com.spring.it; 2 3 import org.springframework.stereotype.Controller; 4 import org.springframework.web.bind.annotation.CookieValue; 5 import org.springframework.web.bind.annotation.RequestMapping; 6 7 import com.spring.bean.Person; 8 9 @Controller10 public class RequestParamControl {11 @RequestMapping("/pojo")12 public String hello(Person person) 13 {14 System.out.println("person="+person);15 return "success";16 }17 }
5.index.jsp
1 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 pageEncoding="ISO-8859-1"%> 3 4 5 6 725 26Insert title here 8 9 10
6.效果