Contents
Do you need a controller for every model?
Do I need a controller for each model? No, not necessarily. However, having one controller per RESTful resource is a convention for a reason, and you should carefully analyze why that convention isn’t meeting your needs before doing something completely different.
Can a model have multiple controllers?
Model – The parts inside that are invoked by the controller that cause the temperature to change. You should always abide by designs that allow loose coupling and limit models and their associated controllers to a single task, and you should use as many modules/controllers as you need.
Can we have multiple controllers in MVC?
In Spring MVC, we can create multiple controllers at a time. It is required to map each controller class with @Controller annotation. Create the controller class. Provide the entry of controller in the web.
What exactly is model in MVC?
The model is how you represent the data of the application. It is the state of the application, the data which would influence the output (edit: visual presentation) of the application, and variables that can be tweaked by the controller.
When should I use multiple controllers?
pretty much whenever you have a different task to complete. If you have something that involves handling users, name your controller users. whatever, then name the actions appropriately (create, edit, update, delete, search, etc.). If you have something that solely does searching, name it search.
Can you have more than one controller per view?
IMO, by only having 1 Controller per View it makes it easier to accomplish this. But I’m sure you could have a Controller with multiple Views and still design it so you can switch Views without changing program logic. One example that I like is thinking of a thermostat.
How many Controllers should I use in MVC architecture?
You should always abide by designs that allow loose coupling and limit models and their associated controllers to a single task, and you should use as many modules/controllers as you need. Depending on the size of your application, you may have far less views than you do models and controllers.
Is it bad to have 50 MVC controllers?
If you have 50 controllers you will also have 50 toplevel folders for views. It will be hard to find the view and controller you need to work on. As others mentioned actions are typically short and its not that bad to have a couple of them in your controller. I tried to have 1 controller by system part.
How many controllers do I need for my database?
A very very rough estimate to get an initial idea could be one controller for every table in your database that users can access. But this is really only a very crude measurement. It really depends on the web app. In your example, one is probably sufficient.