Spring 和 MVC 正确的项目结构 [英] Spring and MVC proper project structure

查看:15
本文介绍了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 接口和实现放在某个地方.我已阅读这篇文章 link 并且建议的项目结构不适合我.我想到的是添加以下内容:

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 目录的内容如下所示(模型目录中有 Client 和 Customer 类):

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 then 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 项目时,您应该跳过选择架构类型.

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

希望对你有帮助.干杯.

Hope this helps you. Cheers.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆