简体   繁体   English

什么是Spring MVC Hibernate应用程序设计?

[英]What is the Spring MVC Hibernate application design?

I learnt Spring MVC few weeks ago, and I want to put this into practice now. 几周前,我学习了Spring MVC,现在想将其付诸实践。

I am about to build an applications that interacts heavily with the database, My question is: 我将要构建一个与数据库进行大量交互的应用程序,我的问题是:

What is the best practice to build a spring mvc 4 application with Hibernate 4, Should I use this design pattern? 使用Hibernate 4构建spring mvc 4应用程序的最佳实践是什么,我应该使用这种设计模式吗?

在此处输入图片说明

Or this: 或这个:

在此处输入图片说明

Or should I use Spring Data JPA instead? 还是应该改用Spring Data JPA?

PS I tried to make the question not so general. PS我试图使这个问题不是那么普遍。

Thanks already. 谢谢了

Spring Data JPA eliminates a lot of the boilerplate code you might need to write for your DAOs, so it is convenient. Spring Data JPA消除了您可能需要为DAO编写的许多样板代码,因此非常方便。 http://www.mkyong.com/ has good tutorials. http://www.mkyong.com/有很好的教程。

JPA is useful in that you can (somewhat) easily change ORMs, for example if you wanted to switch to EclipseLink down the road. JPA很有用,因为您可以(某种程度上)轻松地更改ORM,例如,如果您想在将来切换到EclipseLink。

Regarding package names, I usually use: 关于软件包名称,我通常使用:

com.example.project.
    domain          (JPA entities)
    repository      (SDR JPA repos)
    service         (service classes)
    web
        controller  (Spring MVC Controllers)
        exception   (Custom http exception classes)
        form        (Form backing objects)
        interceptor (HandlerInterceptors)
        validation  (Web-specific validation classes)

Down the road though, you might use a Maven multi-module project and break web into its own module. 不过,在将来,您可能会使用Maven多模块项目并将Web分解为自己的模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM