Spring和MVC正确的项目结构

Spring和MVC正确的项目结构

本文介绍了Spring和MVC正确的项目结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Maven开发Swing独立应用程序。我尝试遵循MVC模式。我对我的项目结构感到困惑。我有这样的事情:

I'm developing Swing standalone application using Maven. I try to follow MVC pattern. I'm confused with my project structure. I have something like this:

/src/main/java/myName/appName
/src/main/java/myName/appName/model
/src/main/java/myName/appName/view
/src/main/java/myName/appName/controller

现在我想要合并Spring框架,是什么让我放置在DAO和BO接口和实现的某个地方。我已阅读本文,建议的项目结构不适合我的。我想到的是添加这个:

Now I want to incorporate Spring framework, what makes me place somewhere DAO and BO interfaces and implementations. I have read this article link and the suggested project structure does not suit mine. What crosses my mind is to add this:

/src/main/java/myName/appName/dao
/src/main/java/myName/appName/bo

dao目录的内容如下所示(使用模型目录中的客户端和客户类):

The content of dao directory would look like this (with Client and Customer classes in model directory):

/src/main/java/myName/appName/dao/ClientDAO.java
/src/main/java/myName/appName/dao/ClientDAOImpl.java
/src/main/java/myName/appName/dao/CustomerDAO.java
/src/main/java/myName/appName/dao/CustomerDAOImpl.java

这不好吗?我想学习好的做法。

Is this bad? I want to learn good practices.

推荐答案

你可以遵循你在问题中定义的两个项目结构中的任何一个但是应该取决于您的应用程序大小。

You can follow any of the two project structure you have defined in your problem but that should depend on your application size.

如果您的应用程序中有大量模块,则可以按照@basijames所述的项目结构进行操作。因为这有助于管理代码并在团队中分配工作。

If you have a large amount of modules in your application than you can follow the project structure as described by @basijames. Because that will be helpful in managing the code and distributing the work in your team.

如果你没有比我更喜欢的模块,你应该去寻找类似的项目结构。下面。

If you don't many modules than I prefer you should go for project structure something like below.

/src/main/java/myName/appName/controller
/src/main/java/myName/appName/model
/src/main/java/myName/appName/service
/src/main/java/myName/appName/dao
/src/main/java/myName/appName/bo

但是根据我创建maven项目时,你应该跳过选择的archtypes。

But according to me while creating a maven project you should skip the selecting archtypes.

希望这会对你有所帮助。干杯。

Hope this helps you. Cheers.

这篇关于Spring和MVC正确的项目结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 05:39