Struts2-Full-Hibernate 插件是集成 Struts2 和 Hibernate 的标准方式吗? [英] Is Struts2-Full-Hibernate plugin the standard way to integrate Struts2 and Hibernate?

查看:21
本文介绍了Struts2-Full-Hibernate 插件是集成 Struts2 和 Hibernate 的标准方式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开始一个项目,愿意使用 Struts2 和 Hibernate.

I'm starting a project, willing to use Struts2 and Hibernate.

我应该使用 struts2-full-hibernate 插件,或者以不同的方式集成它们?

Should I use the struts2-full-hibernate plugin, or integrate them differently ?

在互联网上搜索让我感到困惑:这是集成它们的标准方法吗?如果没有,这是标准方式吗?

Searching on Internet confused me: is it the standard way to integrate them ? If not, which is the standard way ?

推荐答案

简而言之:

  1. 为前端选择一个框架(通常是 MVC,然后是 Struts2JSF2Spring MVC 等等...你'我已经选择了 Struts2.Java EE 6+ 堆栈中的标准(不一定是更好也不是最常用的)是 JSF2);
  2. 选择一个持久性管理器:

  1. Choose a framework for the front-end (usually MVC, then Struts2, JSF2, Spring MVC, etc... you've already chosen Struts2. The standard (not necessarily the better nor the most used) in the Java EE 6+ stack is JSF2);
  2. Choose a persistence manager:

  • Java EE 6+ 的标准是 JPA 2.0(JSR 317 - Java 持久性 API).JPA 只是注解,你需要一个实现它们的库;Hibernate 可以用作 JPA 实现.Hibernate 不是唯一的 JPA 提供者,但它是最常用的(不一定是最好的),因此也是最标准的.使用此配置,您可以通过将表示层(Struts2 操作)与持久层分离来构建应用程序的层,其中执行 CRUD.也不再需要 DAO 层,因为 JPA 的 EntityManager dao 本身.

  • the standard with Java EE 6+ is JPA 2.0 (JSR 317 - Java Persistence API). JPA are just annotations, you need a library implementing them; Hibernate can be used as JPA implementation. Hibernate is not the only JPA provider, but it is the most used one (not necessarily the best one), and hence the most standard. With this configuration, you can structure the application's layers by separating the presentation layer (Struts2 actions) from the persistence layer, where the CRUD is performed. The DAO layer is also not needed anymore because JPA's EntityManager is the dao itself.

否则,您可以使用 raw Hibernate 及其专有注释(或任何其他持久性管理器),在这种情况下,使用 Struts2,您可以使用(复古?)Struts2-Full-休眠插件.它简化了一些工作,但迫使您使用 OSIV(Open-Session-In-View)(反)模式.

You can otherwise use raw Hibernate with its proprietary annotations (or any other persistence manager), and in that case, with Struts2, you can use the (vintage?) Struts2-Full-Hibernate plugin. It simplifies some jobs, but force you to use the OSIV (Open-Session-In-View) (anti)pattern.

选择框架和持久性管理器后,您需要选择DI(依赖注入)管理器.如果您使用的是 Java EE 6+,标准是使用 CDI (JSR 299 - 上下文和依赖注入).在 Java EE 6 之前,或者对于怀旧的开发人员来说,Spring 仍然可用.它是第一个在 Java EE 缺乏时提供 DI/IoC(控制反转)的库.

After having chosen the framework and the persistence manager, you need to chose a DI (Dependency Injection) manager. If you are using Java EE 6+, the standard is to use CDI (JSR 299 - Contexts and Dependency Injection). Before Java EE 6, or for nostalgic developers, Spring is still available. It's been the first library providing DI / IoC (Inversion of Control) when Java EE was lacking it.

特别是,使用 Struts2,您可以:

Specifically, with Struts2 you can:

<小时>

结论

根据Java EE,Struts2(而不是JSF2)的标准配置是:


Conclusion

According to Java EE, the standard configuration with Struts2 (instead of JSF2) is:

  • Struts2
  • Java EE 6+(CDI + JPA 2.x + EJB 3.x)
  • 休眠 4.x
  • Struts2-CDI 插件
  • Struts2
  • Java EE 6+ (CDI + JPA 2.x + EJB 3.x)
  • Hibernate 4.x
  • Struts2-CDI-plugin

这篇关于Struts2-Full-Hibernate 插件是集成 Struts2 和 Hibernate 的标准方式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆