如何将Struts 2与Hibernate和PostgreSQL连接起来 [英] How to connect Struts 2 with Hibernate and PostgreSQL
问题描述
如何将Struts 2与hibernate和PostgreSQL连接?
hibernate.connection.driver_class> org.postgresql.Driver< /性>< property name =hibernate.connection.url> jdbc:postgresql:// localhost / jvmhubtutorial< / property>
< property name =hibernate.connection.username>用户< / property>
< property name =hibernate.connection.password>密码< / property>
您可以通过servlet上下文来集成Hibernate和Struts2,可以共享会话工厂。会话工厂用于打开Hibernate会话并使用它来执行对数据库的查询。这里有一个这样集成的示例。
在Struts2中,没有官方插件来集成Hibernate
框架。但是,您可以通过以下步骤解决:注册一个自定义ServletContextListener
。
- 在
ServletContextListener
类中,初始化Hibernate会话并将其存储到servlet上下文中。
- 在action类中,从servlet上下文获取Hibernate会话,并像平常一样执行Hibernate任务。
How to connect Struts 2 with hibernate and PostgreSQL?
You can integrate Hibernate and Struts2 via servlet context where you can share the session factory. The session factory is used to open Hibernate session and use it to perform queries to the database. Here an example of such integration. In Struts2, there are no official plugins to integrate the Hibernate
framework. But, you can workaround with the following steps :
In Struts2 there's unofficial plugin called Struts2 Full Hibernate Plugin or struts2-s2hibernate that provides an integration with Hibernate. There're examples: 这篇关于如何将Struts 2与Hibernate和PostgreSQL连接起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ b $在Struts2中有非官方的插件叫做Struts2 Full Hibernate Plugin或者
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost/jvmhubtutorial</property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.connection.password">password</property>
ServletContextListener
.ServletContextListener
class, initialize the Hibernate session and store it into the servlet context.