星空网 > 软件开发 > Java

整合struts2+hibernate详细配置步骤及注意事项

刚刚学完这两个框架,就迫不及待的做了一个例子,在整合两个框架的时候,也碰到了一些小问题,下面介绍一下配置的步骤:

1.创建一个自定义的struts2和hibernate的类库

  因为之前写例子都是直接将jar包拖到WEB-INF下的lib包下,但是这里需要导入两个框架的jar包,放在一起的话,会很乱,所以最好是创建自定义的类库:

    1.window->Preferecces->Java->BuildPath->UserLibraries->new.

      整合struts2+hibernate详细配置步骤及注意事项

      以struts2的类库为例,输入struts2-core,点击ok.选中该文件,点击Add External JARs..,找到struts2的核心jar包,全部放进来.完成后点击ok.

      整合struts2+hibernate详细配置步骤及注意事项

  hibernate的jar包,步骤同上.

2.导入struts和hibernate的jar包.

  新建一个Web project,选中当前工程,右键选择最下方的Propertie->Java buildPath->Libraries->Add Libraries->User Libraries.

          整合struts2+hibernate详细配置步骤及注意事项

找到你之前建好的类库,导入即可.

 

3.配置web.

  在web.

 <filter>    <filter-name>struts2</filter-name>    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>  </filter>  <filter-mapping>    <filter-name>struts2</filter-name>    <url-pattern>/*</url-pattern>  </filter-mapping>

4.src目录下创建struts.

<??><!DOCTYPE struts PUBLIC  "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"  "http://struts.apache.org/dtds/struts-2.3.dtd"><struts>  <package name="default" namespace="/" extends="struts-default">  

</package></struts>

5.src目录下创建并配置hibernate.cfg.

<!DOCTYPE hibernate-configuration PUBLIC  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"  "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"><hibernate-configuration>  <session-factory>    <!-- 配置数据库连接信息 -->    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>    <property name="connection.url">jdbc:mysql:///hibernate</property>    <property name="connection.username">root</property>    <property name="connection.password">123</property>    <!-- 配置数据库方言 -->    <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>    <property name="show_sql">true</property>    <property name="format_sql">true</property>    <property name="hbm2ddl.auto">update</property>    <!-- 使用getCurrentSession方式打开会话 -->    <property name="hibernate.current_session_context_class">thread</property>  </session-factory></hibernate-configuration>

到这里,环境已经配置好了,接下来就可以享受框架带来的便利了:)




原标题:整合struts2+hibernate详细配置步骤及注意事项

关键词:Struts

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

美国 fba 敏感货:https://www.goluckyvip.com/tag/37932.html
美国 fba 头程:https://www.goluckyvip.com/tag/37933.html
美国&加拿大劳动节:https://www.goluckyvip.com/tag/37934.html
美国amazon fba:https://www.goluckyvip.com/tag/37937.html
美国amazon选品:https://www.goluckyvip.com/tag/37938.html
第三方物流:https://www.goluckyvip.com/tag/3794.html
2022世界杯门票如何买?:https://www.vstour.cn/a/363182.html
沈阳到本溪的距离有多远?(详细路线及交通方式):https://www.vstour.cn/a/363183.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流