博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
008 使用POJO对象绑定请求参数
阅读量:4331 次
发布时间:2019-06-06

本文共 3337 字,大约阅读时间需要 11 分钟。

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 
7 Insert title here 8 9 10
11 username:
12
13 passwaord:
14
15 email:
16
17 age:
18
19 province:
20
21 city:
22
23
24
25 26

 

6.效果

  

  

 

转载于:https://www.cnblogs.com/juncaoit/p/8419848.html

你可能感兴趣的文章
Hibernate视频学习笔记(8)Lazy策略
查看>>
CSS3 结构性伪类选择器(1)
查看>>
IOS 杂笔-14(被人遗忘的owner)
查看>>
自动测试用工具
查看>>
前端基础之BOM和DOM
查看>>
[T-ARA/筷子兄弟][Little Apple]
查看>>
编译Libgdiplus遇到的问题
查看>>
【NOIP 模拟赛】Evensgn 剪树枝 树形dp
查看>>
java学习笔记④MySql数据库--01/02 database table 数据的增删改
查看>>
两台电脑如何实现共享文件
查看>>
组合模式Composite
查看>>
程序员最想得到的十大证件,你最想得到哪个?
查看>>
我的第一篇CBBLOGS博客
查看>>
【MyBean调试笔记】接口的使用和清理
查看>>
07 js自定义函数
查看>>
jQueru中数据交换格式XML和JSON对比
查看>>
form表单序列化后的数据转json对象
查看>>
[PYTHON]一个简单的单元測试框架
查看>>
iOS开发网络篇—XML数据的解析
查看>>
[BZOJ4303]数列
查看>>