一个简单的用户登录。创建好一个web工程后,添加为Spring工程添加hibernate工程是会将hibernate.cfg.xml集成到applicationContext中既然是用户登录首先需要一个实体类。
[html] view plain copy
[html] view plain copy
[html] view plain copy
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
[html] view plain copy
org.hibernate.dialect.MySQLDialect
true
true
[html] view plain copy
建立实体类User.java
[html] view plain copy
package com.entity;
/**
* User entity. @author MyEclipse Persistence Tools
*/
public class User implements java.io.Serializable {
// Fields
/**
*
*/
private static final long serialVersionUID = 4585221013478533506L;
private Integer id;
private String username;
private String password;
// Constructors
/** default constructor */
public User() {
}
/** full constructor */
public User(String username, String password) {
this.username = username;
this.password = password;
}
// Property accessors
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
}
[html] view plain copy
放到control中,每次请求就++即可。