这个GWT模块结构好吗?

发布于 2024-10-12 15:27:02 字数 1683 浏览 9 评论 0原文

描述

我有一个使用 gwt-maven-plugin 的父 GWT 项目。该项目分为 2 个子项目:Domain 和 WebApp,每个项目都包含 pom.xml 文件。我想将域代码与 GWT 客户端代码分开。

父项目

  • /Parent
  • /Parent/pom.xml

域项目

[1] 我将其视为在服务器上运行的应用程序的服务器端部分

  • /Parent/Domain
  • /Parent/Domain/pom.xml
  • .../ beans/PersonBean.java
  • .../dao/PersonDAO.java
  • .../services/PersonService.java
  • .../util/DateUtil.java
  • .../gwt/client/GWTPersonService.java
  • .../gwt/server /GWTersonServiceImpl.java
  • .../gwt/shared/GWTersonDTO.java -- 一个 DTO(数据传输对象)

WebApp 项目

[2] 我将其视为在 Web 浏览器中运行的应用程序的客户端。

  • Parent/WebApp
  • Parent/WebApp/pom.xml
  • .../gwt/client/PersonUI.java
  • .../gwt/util/GWTUtility.java - 这是 GWT 组件调用的实用程序类,不在服务器上使用
  • .../webapp/WEB-INF/web.xml
  • .../webapp/Page.css
  • .../webapp/Page.html

序列图

alt text

PersonUI 将调用 GWTersonService 的方法,该方法调用 PersonService(我需要这种分离,因为非 GWT 客户端也会调用 PersonService.java)。

PersonService 将调用 PersonDAO,后者使用并返回 PersonBean 实例。然后,PersonBean 转换为 GWTersonDTO 并通过 GWTersonServiceImpl 发送到客户端。

问题(已编辑)

  1. 我应该将通常位于 /shared 文件夹下的共享 GWT 代码放在哪个项目中?
  2. 在域项目中包含 GWTPersonServiceImpl.java 和 GWTPersonService.java 是否有意义?我的原因是,由于所有 servlet 都位于服务器上,并且域用于服务器端,那么这些类应该位于域项目中。
  3. 我应该将 GWTUtility.java 移到域项目中吗?
  4. 使用 DTO 有意义吗?有没有办法让它更直接:即直接使用PersonBean?
  5. 是否可以使用 Maven 在 GWT 开发人员模式下运行此场景?配置有多容易?
  6. 如果您对上述场景有任何修改/添加,请发布它们 - 或者如果您已经完成了一个应用程序,那么更好的是了解您如何解决这种分离问题。

谢谢你!

Description

I have a Parent GWT project that uses the gwt-maven-plugin. This project is split into 2 sub-projects: Domain and WebApp and each project contains pom.xml files. I'd like to split the domain code from GWT client code.

Parent project

  • /Parent
  • /Parent/pom.xml

Domain project

[1] I think of of it as the server-side part of the application that runs on the server

  • /Parent/Domain
  • /Parent/Domain/pom.xml
  • .../beans/PersonBean.java
  • .../dao/PersonDAO.java
  • .../services/PersonService.java
  • .../util/DateUtil.java
  • .../gwt/client/GWTPersonService.java
  • .../gwt/server/GWTPersonServiceImpl.java
  • .../gwt/shared/GWTPersonDTO.java -- a DTO(Data Transfer Object)

WebApp project

[2] I think of it as the client-side of the application that runs in the web browser.

  • Parent/WebApp
  • Parent/WebApp/pom.xml
  • .../gwt/client/PersonUI.java
  • .../gwt/util/GWTUtility.java - this is a utility class called by GWT components, it is not used on the server
  • .../webapp/WEB-INF/web.xml
  • .../webapp/Page.css
  • .../webapp/Page.html

Sequence diagram

alt text

PersonUI will call GWTPersonService's methods which calls PersonService(I need this separation because PersonService.java will be called by non-GWT clients as well).

PersonService will call PersonDAO which uses and returns PersonBean instances. Then, PersonBean gets converted to GWTPersonDTO and sent to the client by GWTPersonServiceImpl.

Questions (edited)

  1. In which project should I put the shared GWT code that normally lives under /shared folder?
  2. Does it make sense to have GWTPersonServiceImpl.java and GWTPersonService.java in the domain project? My reason is that since all servlets live on the server, and the domain is for server-side then those classes should be in the Domain project.
  3. Should I move GWTUtility.java inside Domain project?
  4. Does it make sense to use DTO's? Is there any way to make it more straight-forward: i.e. use directly the PersonBean?
  5. Is it possible to run this scenario in GWT Developer mode using maven? How easy is it to configure?
  6. If you have any modifications/additions to the above scenario, please post them - or even better if you have already done an app it would help much to know how you did to solve this separation.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无戏配角 2024-10-19 15:27:02
  1. 我会将共享代码放在域和 WebApp 都可以依赖的第三个项目中。
  2. 由于 GWTPersonServiceImpl 是一个 servlet 并且在服务器上运行,而不是在客户端上运行,因此它属于域。
  3. GWTUtility 执行什么功能?如果只用在客户端,则属于WebApp;如果它只在服务器上使用,那么它属于域;如果两者都使用它,那么它可能属于 WebApp 和 Domain 都依赖的第三个项目。
  4. 您可以使用复杂类型,只要它(及其组成类型)实现 com.google.gwt.user.client.rpc.IsSerialized 或(有限制)java.io.Serialized 。有关详细信息,请参阅GWT 开发指南。无论如何,按照设计,项目中的任何序列化类型都可能属于 Domain 和 WebApp 所依赖的模块。
  5. 是的。
  1. I would put the shared code in a third project on which both Domain and WebApp can depend.
  2. Since GWTPersonServiceImpl is a servlet and runs on the server, not the client, it belongs in Domain.
  3. What function does GWTUtility perform? If it is only used on the client, it belongs in WebApp; if it is only used on the server then it belongs in Domain; if it is used on both then it probably belongs in a third project on which both WebApp and Domain depend.
  4. You can use a complex type as long as it (and its constituent types) implements either of com.google.gwt.user.client.rpc.IsSerializable or (with limitations) java.io.Serializable. See the GWT development guide for details. In any case, as designed, any serialized type in your project probably belongs in a module upon which both Domain and WebApp depend.
  5. Yes.
那请放手 2024-10-19 15:27:02

我的管理方式如下:

Commons
    CmnDomain [Java Project]
        src/java/com/cmnapp/CmnDomain.gwt.xml // specifying "domain" as source
        src/java/com/cmnapp/domain //  POJO's used in GWT application
        src/java/com/cmnapp/iBatis //  iBatis implementation (you can have ur DAO impl. here)
        src/java/com/myapp/service //  Common Spring service
MyApp
    MyAppService [Java Project]
        src/java/com/mynapp/MyAppDomain.gwt.xml  //  specifying "domain" as source
        src/java/com/mynapp/domain //  POJO's used in GWT application
        src/java/com/mynapp/iBatis //  iBatis implementation (you can have ur DAO impl. here)
        src/java/com/myapp/service //  Spring service
    MyAppWeb [Gwt Web Project]
        src/java/com/mynapp/MyApp.gwt.xml  //  specifying "client" and "shared" as source folders
        src/java/com/myapp/client  //  Pure GWT code can be excluded from .jar of this project
        src/java/com/myapp/shared  //  Shared between UI and Presentation tiers e.g. constants
        src/java/com/myapp/server  //  RPC servlet, Standard servlet, struts action, etc.
        src/webapp/WEB-INF/web.xml
        src/webapp/images //  images
        src/webapp/javascript //  custom java scripts
        src/webapp/css //  cascade style sheets
        src/webapp/WEB-INF/jspx //  internal access only
        src/webapp/secure  //  content accessible post user login
        src/webapp/login   //  content accessible with/without login

I manage it as follows:

Commons
    CmnDomain [Java Project]
        src/java/com/cmnapp/CmnDomain.gwt.xml // specifying "domain" as source
        src/java/com/cmnapp/domain //  POJO's used in GWT application
        src/java/com/cmnapp/iBatis //  iBatis implementation (you can have ur DAO impl. here)
        src/java/com/myapp/service //  Common Spring service
MyApp
    MyAppService [Java Project]
        src/java/com/mynapp/MyAppDomain.gwt.xml  //  specifying "domain" as source
        src/java/com/mynapp/domain //  POJO's used in GWT application
        src/java/com/mynapp/iBatis //  iBatis implementation (you can have ur DAO impl. here)
        src/java/com/myapp/service //  Spring service
    MyAppWeb [Gwt Web Project]
        src/java/com/mynapp/MyApp.gwt.xml  //  specifying "client" and "shared" as source folders
        src/java/com/myapp/client  //  Pure GWT code can be excluded from .jar of this project
        src/java/com/myapp/shared  //  Shared between UI and Presentation tiers e.g. constants
        src/java/com/myapp/server  //  RPC servlet, Standard servlet, struts action, etc.
        src/webapp/WEB-INF/web.xml
        src/webapp/images //  images
        src/webapp/javascript //  custom java scripts
        src/webapp/css //  cascade style sheets
        src/webapp/WEB-INF/jspx //  internal access only
        src/webapp/secure  //  content accessible post user login
        src/webapp/login   //  content accessible with/without login
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文