说明:本文档,是和struts2+hibernate的整合示例。
lib下还有struts2的jar包,本示例没有显示。struts2的搭建参考struts2的环境搭建
一下载hibernate的jar包,并将相关jar包导入的项目web-inf的lib下
少了一个jar包,报错
二:配置hibernate.cfg.xml文档
1 <!DOCTYPE hibernate-configuration PUBLIC 2 "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 3 "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 4 5 <hibernate-configuration> 6 <session-factory > 7 <!-- 全局开发配置 --> 8 9 <!-- hibernate 会自动生成sql。 为了能够屏蔽 数据库的差异。 需要配置 数据库方言--> 10 <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> 11 12 <!-- 如果数据库中无相应的表的话,则自动生成一个与po对应的表 --> 13 <property name="hibernate.hbm2ddl.auto">update</property> 14 15 <!-- 在服务器后台打印出hibernate映射的sql语句 --> 16 <property name="hibernate.show_sql" >true</property> 17 <!-- sql语句格式化输出 --> 18 <property name="format_sql">true</property> 19 20 21 <!-- 数据库连接信息 --> 22 <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 23 <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property> 24 <property name="hibernate.connection.username">root</property> 25 <property name="hibernate.connection.password">1234</property> 26 27 28 29 <!-- java和数据的桥梁,映射java的实体类和数据库中的表 --> 30 <mapping resource="com/bjsxt/shangxiaofei/po/User.hbm.xml"></mapping> 31 32 </session-factory> 33 </hibernate-configuration>