javabean封装类
package cn
.day
.domain
;
import java
.io
.Serializable
;
public class Acccount implements Serializable {
private String username
;
private String password
;
private String sex
;
private User user
;
public String
getUsername() {
return username
;
}
public void setUsername(String username
) {
this.username
= username
;
}
public String
getPassword() {
return password
;
}
public void setPassword(String password
) {
this.password
= password
;
}
public String
getSex() {
return sex
;
}
public void setSex(String sex
) {
this.sex
= sex
;
}
public User
getUser() {
return user
;
}
public void setUser(User user
) {
this.user
= user
;
}
@Override
public String
toString() {
return "Acccount{" +
"username='" + username
+ '\'' +
", password='" + password
+ '\'' +
", sex='" + sex
+ '\'' +
", user=" + user
+
'}';
}
}
详解
private User user:此处是一个对象类型的隐藏类型的数据。
生成该对象的get,set方法同时生成所有方法的toString方法
User类
package cn
.day
.domain
;
import java
.io
.Serializable
;
public class User implements Serializable {
private String uname
;
private Integer age
;
public String
getUname() {
return uname
;
}
public void setUname(String uname
) {
this.uname
= uname
;
}
public Integer
getAge() {
return age
;
}
public void setAge(Integer age
) {
this.age
= age
;
}
@Override
public String
toString() {
return "User{" +
"uname='" + uname
+ '\'' +
", age=" + age
+
'}';
}
}
详解
生成数据的set,get方法生成数据的toString方法
HTML部分
nname:
<input type="text" name="user.uname"/><br/>
年龄:
<input type="text" name="user.age"/><br/>
user.uname:隐藏类型的表单对象的私有属性。