SSH集成時不用hbm.xml文件的配置方法

在beans.xml配置文件(applicationContext.xml)中將java

<property name="mappingResources">
<list>
<value>cw/test/bean/Employee.hbm.xml</value>
</list>
</property>
app

的映射關係刪除,改爲:this

<property name="annotatedClasses">
<list><value>cw.test.bean.Employee</value></list>
</property>
spa

其中cw.test.bean.Employee爲實體類xml


具體的實體類改爲以下形式,加入註解:get

@Entity
@Table(name="employee")
public class Employee implements java.io.Serializable{
@Id
@Column(name="username")
private String username;

@Column(name="password")
private String password;

@Enumerated(EnumType.STRING)
private Gender gender = Gender.MAN;

public Employee(){}

public Employee(String username, String password){
this.username = username;
this.password = password;
}

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 Gender getGender() {
return gender;
}
public void setGender(Gender gender) {
this.gender = gender;
}

}
it

須要注意的是若是某個字段是用的枚舉類型,那麼須要用到Enumerated註解,而且在實體類上要實現java.io.Serializable類。io

相關文章
相關標籤/搜索