can request be validated before reaching the controller?
hey guys. im talking with a friend of mine and he mentioned that in php language you usually validate the data BEFORE it reaches the controller. i was wondering if this can be done in Java Spring app? as i understand this idea cant be done in Java Spring app. the controller in Spring app is the entry point to the application. and you cant really do much in Dispatcher servlet. what do you guys think? thanks in advance.
12 Replies
⌛
This post has been reserved for your question.
Hey @Fragmented friends! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
In classical spring/spring boot it's the controllers duty to parse and validate inputs
So your friend might be talking about a different framework where they name something else a controller
yeah, hes talking about Php Symfony
🤷 , to me he sounds wrong
but it makes sense. it follows "fail early and fast" idea. you know, like "return early" rule
yes, the first place where you can... the controller
I think if you just do
@Validated
etc, without an Errors
parameter, Spring validates it before and doesn't even let the request to the controller (400 to the client or calling a handler you specified I think)yeah, but you put those, in the controller 😄
as annotations
the logic itself isn't in the controller ;)
Just as it does the json to object conversion etc
yeah I would consider these as happeneing before reaching the controller
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.