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
JavaBot
JavaBot3w ago
This post has been reserved for your question.
Hey @Fragmented friends! Please use /close or the Close 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.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
tjoener
tjoener3w ago
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
i hate SQL so much its unreal
yeah, hes talking about Php Symfony
tjoener
tjoener3w ago
🤷 , to me he sounds wrong
i hate SQL so much its unreal
but it makes sense. it follows "fail early and fast" idea. you know, like "return early" rule
tjoener
tjoener3w ago
yes, the first place where you can... the controller
dan1st
dan1st3w ago
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)
tjoener
tjoener3w ago
yeah, but you put those, in the controller 😄
dan1st
dan1st3w ago
as annotations the logic itself isn't in the controller ;)
tjoener
tjoener3w ago
Just as it does the json to object conversion etc
dan1st
dan1st3w ago
yeah I would consider these as happeneing before reaching the controller
JavaBot
JavaBot3w ago
💤 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.

Did you find this page helpful?