how do you define what is model or entity in MVC?
most of my Spring codes had package strucure like his: http://www.mkyong.com/spring-mvc/spring-mvc-form-handling-example/
I have my view, my controller, my dao and "the model" for the dao
but I try to learn thymeleaf and found this: https://github.com/thymeleaf/thymeleafexamples-stsm
there is no "model"package, he call it entity, it is an entity but..
then I thought...oh wait a minute...what is the definition of entiy and model? similar to this question: Entity vs Model vs View Model
so what is your package structre, do you call it model or entity? do you have maybe examples of the packagenames/structure of your spring projects?
Literally, a Model
is a class for representing POJO. Entity
- has relation to DB.
Sometimes they are mixed together, like:
package net.lelyak.edu.entity;
@Entity
public class User extends BaseEntity {
// fields + get/set
The structure depends on a convention of your project or team.
If it is your personal project you can fully decide which package structure you want to follow.
Here is some way which I did for my spring training:
However, for your own purpose, you can fully decide how to manage packages, following are also legit:
The main idea is that no strict borders for it.
For the personal project, it has to be a convenience for you.
When you collaborating with others on the same project, you have to agree on it together.
My Spring projects most have a package structure like below. This structure is my base structure for dao
, services
, implementations
, view
and util
. Sure the structure can change and all that depends on what you have to develop.
com.companyName.appName.config ->
I use config for my classes which are annotated with @Configuration.
com.companyName.appName.dao.model ->
I use dao.model for all my entities from the DB.
com.companyName.appName.dao.repository ->
I use dao.repository for all the repositories used with spring-data-jpa.
com.companyName.appName.dao.repository.impl ->
I use dao.repository.impl for all customized implementations of repositories.
For example to autowire the entityManager.
com.companyName.appName.service ->
I use service for all my service interfaces
com.companyName.appName.service.impl ->
I use service.impl for all my implementations of services
com.companyName.appName.controller ->
I use controller for all my controllers.
com.companyName.appName.view.model ->
I use view.model for all my frontend specific models which are no enitites.
com.companyName.appName.view.form ->
I use view.form for all my frontend specific forms which has to be submitted and validated.
com.companyName.appName.util ->
I use util for utility stuff.
I hope this gives you a short overview how I structure my packages for spring-boot applications. But everybody like to have its own naming. So its very difficult to make it general.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With