如何连接 Java EE 应用程序中的各个部分
我正在制作一个 Java EE 应用程序,只是为了使用我在书中学到的知识。我创建了一个简单的实体和一个 DAO 对象,该对象对该实体执行不同的操作,例如创建、更新等。然后在我的 EJB 中,我想使用这个 DAO 对象,以便稍后可以将其公开给 JSF 等。
我有一点理解如何在应用程序的不同层中使用不同类的对象的问题。我如何将它们暴露给彼此?
我是否只是像常规 Java SE 中那样做?拥有不同类的属性并在我想要的类中实例化它们? (不,可能不是,我已经看到了 @Inject 等的使用,但我一点也不理解。而且当我可以使用它时也不理解)
我会欣赏一些关于何时/如何使用不同注释的文本以及我们如何连接不同的层,而不仅仅是一些显示它的代码。
如果有人有空闲时间的话我会参加 Java 聊天 =)
I am making a Java EE application just to use what I learn while reading in the books. I made a simple Entity and a DAO object that do different actions on this Entity such as create, update etc. Then in my EJB I want to use this DAO object so that I later can expose it to JSF etc.
I am having a little problems of understanding how to use objects of different classes in different layers of my application. How do I expose them to each other?
Do I just do as in regular Java SE? Have properties for the different classes and instantiate them in the classes I want? (No probably not, I have seen the use of @Inject and so on, but I do not understand one bit of it. And not when I can use it either)
I would apprciate some text on when/how we use the different annotations and how we connect different layers rather than just some code showing it.
I am on the Java chat if anyone have some spare time =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你问的问题太笼统了。找一些关于 Java EE 的不错的书(有很多)。为了更好地理解依赖注入,我推荐官方Weld
JPA Entity:
EJB bean:
JSF 控制器(我们假设它是 CDI-bean):
xhtml 页面:
更新
一些可能有帮助的书:
这些非常受欢迎并且涵盖了很多领域。
You're asking too general questions. Grab some decent book on Java EE (there are tons of them). For better understanding of dependency injection, I'd recommend official Weld documentation. However here is a typical example aimed to show you how to connect different Java EE layers:
JPA Entity:
EJB bean:
JSF controller (let's assume it's CDI-bean):
xhtml page:
Update
Some books that might help:
These are quite popular and cover a lot of ground.