CREATE DATABASE MYHIBERNATE; USE MYHIBERNATE; CREATE TABLE ARTICLES( id BIGINT NOT NULL, title VARCHAR(255) NOT NULL, content TEXT NOT NULL, writeDate DATE, PRIMARY KEY(id));
step4:
创建持久化类EntityArticle.java,代码如下:
package com.ouxingning.hibernate; /** * <p>Title: articlesManage project</p> * * <p>Description: manage articles</p> * * <p>Copyright: Copyright (c) 2005</p> * * <p>Company: </p> * * @author ouxingning * @version 1.0 */import java.io.*; import java.sql.Date; public class EntityArticle implements Serializable { private Long id; private String title; private String content; private String remark; private Date writeDate; public EntityArticle() { } private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { ois.defaultReadObject(); } private void writeObject(ObjectOutputStream oos) throws IOException { oos.defaultWriteObject(); } public void setId(Long id) { this.id = id; } public void setTitle(String title) { this.title = title; } public void setContent(String content) { this.content = content; } public void setRemark(String remark) { this.remark = remark; } public void setWriteDate(Date writeDate) { this.writeDate = writeDate; } public Long getId() { return id; } public String getTitle() { return title; } public String getContent() { return content; } public String getRemark() { return remark; } public Date getWriteDate() { return writeDate; }}
在这个简单的文章发布应用中,我们使用了Struts作为表现层框架,使用了Hibernate作为持久化层框架,大大增强的应用的可扩展性和可维护性。各位对Struts或Hibernate感爱好的朋友可以继续扩展该应用,在扩展过程中,《Struts in Action》,《Hibernate in Action》以及Hibernate的文档都是很好的参考资料。