set注入的3种方式【非引用类型】

1、com.tz.model.UserBean.java

package com.tz.model;

import java.util.Date;

/**
 * 用户信息 
 * 创建人:LiPiaoShui
 * 时间:2015年12月7日-下午4:44:15
 * @version 1.0.0
 */
public class UserBean {
	
	private Integer id;
	private String username;
	private String password;
	private Integer age;
	private String address;
	private String email;
	private Date createTime;
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer 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 Integer getAge() {
		return age;
	}
	public void setAge(Integer age) {
		this.age = age;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public Date getCreateTime() {
		return createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	@Override
	public String toString() {
		return "UserBean [id=" + id + ", username=" + username + ", password="
				+ password + ", age=" + age + ", address=" + address
				+ ", email=" + email + ", createTime=" + createTime + "]";
	}
	
}

2、第1种方式

<bean id="user1" class="com.tz.model.UserBean">
	<!-- spring2.x写法 -->
	<property name="id"><value>1002</value></property>
	<property name="username"><value>keke2</value></property>
	<property name="password"><value>654321</value></property>
	<property name="age"><value>35</value></property>
	<property name="address"><value>湖南潭州</value></property>
	<property name="email"><value>[email protected]</value></property>
</bean>

3、第2种方式【推荐】

<bean id="user2" class="com.tz.model.UserBean">
	<!-- spring3.x写法 -->
	<property name="id" value="1001" />
	<property name="username" value="keke" />
	<property name="password" value="123456" />
	<property name="age" value="30" />
	<property name="address" value="湖南长沙" />
	<property name="email" value="[email protected]" />
</bean>

4、第3种方式

<bean id="user3" class="com.tz.model.UserBean" 
	p:id="1003"
	p:username="keke3"
	p:password="111111"
	p:age="40"
	p:address="湖北武汉"
	p:email="[email protected]">
</bean>

猜你喜欢

转载自lipiaoshui2015.iteye.com/blog/2265747