给自己一点时间接受自己,爱自己,趁着下午茶的时间来学习图老师推荐的利用开源项目Hibernate开发Blog系统,过去的都会过去,迎接崭新的开始,释放更美好的自己。
【 tulaoshi.com - 编程语言 】
开发工具采用MYECLIPS3.6,首先是建立项目,导入STRUTS+HIBERNATE包,然后配置SRC跟目录下的hibernate.cfg.XML.我采用的是mysql数据库,所以配置如下:<hibernate-configuration>mapping为JavaBEAN所对应的映射。
<session-factory>
<!-- properties -->
<property name="connection.username">root</property>
<property name="connection.url">jdbc:mysql://localhost:3306/tonnyblog</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="connection.passWord"></property>
<property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>
<!-- mapping files -->
<mapping resource="com/tonny/blog/bean/User.hbm.xml"/>
<mapping resource="com/tonny/blog/bean/Item.hbm.xml"/>
<mapping resource="com/tonny/blog/bean/Review.hbm.xml"/>
</session-factory>
</hibernate-configuration>
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
/**
* Description of the Class
*
* @author tonny
* @created 2004年2月6日
*/
public class HibernateUtil {
private final static SessionFactory sessionFactory;
static {
try {
sessionFactory =
new Configuration().configure().buildSessionFactory();
} catch (HibernateException ex) {
throw new RuntimeException(
"Exception building SessionFactory: " + ex.getMessage(),ex);
}
}
private HibernateUtil(){
}
/**
* Description of the Field
*/
private final static ThreadLocal session = new ThreadLocal();
/**
* Description of the Method
*
* @return Description of the Return Value
来源:http://www.tulaoshi.com/n/20160219/1620368.html
看过《利用开源项目Hibernate开发Blog系统》的人还看了以下文章 更多>>