Answer the question
In order to leave comments, you need to log in
What is the best way to handle a custom exception in Spring MVC?
It is necessary to avoid adding a duplicate entry in the controller.
Controller:
CategoryDao:
How ok is it to be tied to the logic of the thrown exception? like in the #isExistByName method?
If it's not ok to do this, then what approach is better to use? rewrite the method that will check if there is an entry in the database without calling the third-party #getByName method?
I re-read and reviewed many examples, but I don’t know what architectural solution to come to.
Answer the question
In order to leave comments, you need to log in
Good evening.
1) First of all - instead of screenshots, add code snippets. If, for example, you have to make changes to your code, then what do you want to do? Do not reprint it from the screen.
2) It is better to transfer the check for duplicates and other logic to the service layer.
For example, a certain CategoryService, where the business logic is processed, and then the CategoryDao methods are called in the service layer
3)
How ok is it to be tied to the logic of the thrown exception?
@ExceptionHandler
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question