P
P
postya2019-04-26 08:57:25
Java
postya, 2019-04-26 08:57:25

How to understand what controllers are needed for a web application on Spring Boot?

I am learning Spring Boot. As far as I understand, controllers are responsible for displaying html pages and responding to user requests.
For example, if there is a web application that has 6 tabs:
-Properties
-Chat
-Calendar
-Offers
-Documents
-Settings
5cc29d630a53d258548436.jpeg
Each tab is a separate html page
Create 6 controllers for each page in this case?
How to understand which controllers and how many are needed for a web application?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Frozen Coder, 2019-04-26
@postya

What prevents you from creating them as needed? Moreover, you can generally make one uber-controller that will respond to everything, but never do it :)
Controllers should be divided according to their field of activity, according to the problem they solve. It can give not only pages, but also some kind of json - you can have dynamic content on the page that you need to get without reloading the entire page. What if it is also needed on another page? For example, a list of users. We have a page for displaying a list of users and we give this page in the user controller, but somewhere on another page we also need to display a list of users or even give it simply through REST to another system, it is logical to place the method returning the json list of users in the same controller.
Another way is to divide your controllers into controllers that serve pages and controllers that serve json. You could say it's a matter of taste.
You start to do, and then you will understand how it is more convenient for you. No need to rush to do all the controllers at once, do all the layers gradually over the areas, then move on to another area. You can go back and edit something. Break the task into subtasks (decompose) according to the features of your application and cut them into features.
And if you work in tandem with a frontender, then be sure to discuss with him what kind of API and data he needs on the client - this will also help you solve your problems with controllers.

A
Anatoly Shipitsyn, 2019-04-26
@norguhtar

Controllers are best divided into groups and functionality. Each controller should be responsible for its own small and self-sufficient piece of action. By itself, spring does not impose any restrictions on how processing will be organized.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question