代码都在这儿求给为大侠给瞅瞅
数据库里有一个user表,三个字段id,username,password
_________________________________
User.java:
public class User implements java.io.Serializable
{
private int id;
private String username;
private String password;
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 User(String username, String password)
{
super();
this.username = username;
this.password = password;
}
}
___________________________________________________
UserDao.java
public interface UserDao
{
public abstract boolean addUser(User user);
}
---------------------
UserDaoImpl.java
public class UserDaoImpl implements UserDao
{
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory)
{
this.sessionFactory = sessionFactory;
}
@Override
public boolean addUser(User user)
{
try {
HibernateTemplate hibernateTemplate =new HibernateTemplate(sessionFactory);
hibernateTemplate.saveOrUpdate(user);
return true;
} catch (DataAccessException e) {
e.printStackTrace();
return false;
}
}
}
--------------------------
RegisterAction.java:
{
private User user;
private UserDaoImpl userDaoImpl;
public User getUser()
{
return user;
}
public void setUser(User user)
{
this.user = user;
}
public void setUserDaoImpl(UserDaoImpl userDaoImpl)
{
this.userDaoImpl = userDaoImpl;
}
@Override
public String execute() throws Exception
{
if(userDaoImpl.addUser(user))
return SUCCESS;
else
return INPUT;
}
}
---------------------
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/spring_hibernate</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>123321</value>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource"/>
</property>
</bean>
<bean id="userDaoImpl" class="com.jeedroid.daoimpl.UserDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="registerAction" class="com.jeedroid.action.RegisterAction">