本文将介绍如何使用SSH框架开发一个简单的用户注册程序。
注:由于在开发本注册程序的时候,报出了 java.lang.ClassNotFoundException: org.hibernate.service.jta.platform.spi.JtaPlatform等错误,网上说的是spring3与hibernate4的整合的确会有错误。,所以本项目中使用的hibernate修改为使用hibernate3.6.7
1.在mysql数据库中创建数据库test ,并在test中创建user数据表
2.在src目录下创建com.integration.entity包,然后在该包下创建持久化类以及映射文件
package com.integration.entity;
public class User implements java.io.Serializable{
private int id;
private String name;
private String password;
public User(){
}
public User(int id, String name, String password) {
this.id = id;
this.name = name;
this.password = password;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.hibernate.entity.User" table="user">
<id name="id" column="user_id" type="java.lang.Integer">
<generator class="increment"/>
</id>
<property name="name" type="java.lang.String" column="name" length="20"></property>
<property name="password" type="java.lang.String" column="password" length="12"></property>
</class>
</hibernate-mapping>
3.在src目录下创建com.integration.dao包,然后在该包下创建DAO接口UserDAO.java、DAO实现类UserDAOImpl.java
package com.integration.dao;
import com.integration.entity.User;
public interface UserDAO {
void save(User user);
}