这个GWT模块结构好吗?
描述
我有一个使用 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
序列图
PersonUI 将调用 GWTersonService 的方法,该方法调用 PersonService(我需要这种分离,因为非 GWT 客户端也会调用 PersonService.java)。
PersonService 将调用 PersonDAO,后者使用并返回 PersonBean 实例。然后,PersonBean 转换为 GWTersonDTO 并通过 GWTersonServiceImpl 发送到客户端。
问题(已编辑)
- 我应该将通常位于 /shared 文件夹下的共享 GWT 代码放在哪个项目中?
- 在域项目中包含 GWTPersonServiceImpl.java 和 GWTPersonService.java 是否有意义?我的原因是,由于所有 servlet 都位于服务器上,并且域用于服务器端,那么这些类应该位于域项目中。
- 我应该将 GWTUtility.java 移到域项目中吗?
- 使用 DTO 有意义吗?有没有办法让它更直接:即直接使用PersonBean?
- 是否可以使用 Maven 在 GWT 开发人员模式下运行此场景?配置有多容易?
- 如果您对上述场景有任何修改/添加,请发布它们 - 或者如果您已经完成了一个应用程序,那么更好的是了解您如何解决这种分离问题。
谢谢你!
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
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)
- In which project should I put the shared GWT code that normally lives under /shared folder?
- 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.
- Should I move GWTUtility.java inside Domain project?
- Does it make sense to use DTO's? Is there any way to make it more straight-forward: i.e. use directly the PersonBean?
- Is it possible to run this scenario in GWT Developer mode using maven? How easy is it to configure?
- 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
GWTPersonServiceImpl
是一个 servlet 并且在服务器上运行,而不是在客户端上运行,因此它属于域。GWTUtility
执行什么功能?如果只用在客户端,则属于WebApp;如果它只在服务器上使用,那么它属于域;如果两者都使用它,那么它可能属于 WebApp 和 Domain 都依赖的第三个项目。com.google.gwt.user.client.rpc.IsSerialized
或(有限制)java.io.Serialized
。有关详细信息,请参阅GWT 开发指南。无论如何,按照设计,项目中的任何序列化类型都可能属于 Domain 和 WebApp 所依赖的模块。GWTPersonServiceImpl
is a servlet and runs on the server, not the client, it belongs in Domain.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.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.我的管理方式如下:
I manage it as follows: