Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring and MVC proper project structure

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.

like image 670
user1091733 Avatar asked Sep 13 '12 00:09

user1091733


People also ask

What is the recommended project structure for spring boot rest projects?

There is no specific layout or code structure for Spring Boot Projects. However, there are some best practices followed by developers that will help us too. You can divide your project into layers like service layer, entity layer, repository layer,, etc. You can also divide the project into modules.

How do I run a Spring MVC project?

Step 1: Create New Spring Project from the menu. Step 2: In the new project window, give the name as “SpringMVCExample” and chose template as “Spring MVC Project”. If you are using this template for the first time, STS will download it from SpringSource website.

What are the four parts that make up Spring MVC configuration?

@RequestMapping annotation maps web requests to Spring Controller methods. The terms model, view, and controller are as follows: Model: The Model encapsulates the application data. View: View renders the model data and also generates HTML output that the client's browser can interpret.


1 Answers

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.

like image 106
basiljames Avatar answered Oct 02 '22 00:10

basiljames