javaBean分析

package com.ldf.domain;
/**
 * 实体bean
 */
import java.io.Serializable;
import java.util.Date;

public class User implements Serializable{
	
	private int id;
	private String username; 
	private String password;
	private String email;
	private Date birthday;
	
	public User() {
		super();
	}
	
	public User(int id, String username, String password, String email,
			Date birthday) {
		super();
		this.id = id;
		this.username = username;
		this.password = password;
		this.email = email;
		this.birthday = birthday;
	}
	@Override
	public String toString() {
		return "User [id=" + id + ", username=" + username + ", password="
				+ password + ", email=" + email + ", birthday=" + birthday
				+ "]";
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	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 getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public Date getBirthday() {
		return birthday;
	}
	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}
}

1.实现Serializable接口是为了服务器重启或者内存溢出之后,能够实现session的钝化和激活两种状态,钝化表示session数据能够进行存盘操作,激活表示服务器从盘中读取session数据.

public class User implements Serializable{

2.字段的定义统一小写且约定必须符合四者的统一,javaBean中的字段定义,前端页面的标签name值,后台request.getParameter的形参,以及数据库中字段的定义要保持一致.

	private int id;
	private String username; 
	private String password;
	private String email;
	private Date birthday;

3.在不写任何构造器的情况下,系统会默认给出无参构造器,但如果给出了有参构造器,那么必须显式的给出无参构造器.构造器的作用在于初始化参数.

	public User() {
		super();
	}
	
	public User(int id, String username, String password, String email,
			Date birthday) {
		super();
		this.id = id;
		this.username = username;
		this.password = password;
		this.email = email;
		this.birthday = birthday;
	}

4.重写toString方法,单纯调用对象时,系统会自动调用toString方法,如果没有重写toString方法,那么会调用Object超级父类的toString方法,执行结果是该对象的地址值.重写该toString方法后,系统也会自动调用toString方法,但是是调用重写后的toString方法.输出的是自定义的信息.

	@Override
	public String toString() {
		return "User [id=" + id + ", username=" + username + ", password="
				+ password + ", email=" + email + ", birthday=" + birthday
				+ "]";
	}

5.getter/setter方法的作用在于调用封装后的字段,在框架中是具有调用属性的作用.

转载于:https://www.cnblogs.com/liu1275271818/p/10107097.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值