Spring and MVC proper project structure

2019-01-17 04:20发布

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

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

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.

2条回答
Bombasti
2楼-- · 2019-01-17 04:55

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

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

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

Hope this helps you. Cheers.

查看更多
再贱就再见
3楼-- · 2019-01-17 04:57

The categorisation

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

will cause problems for you later.
The package structure mentioned in the link you provided should suit you. You should have one package for each module/entity.
Eg /src/main/java/myName/appName/customer
and you should put all model, view, controller and dao classes related to customer in this package.

查看更多
登录 后发表回答