Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about @Valide in Todo project #21

Open
sunbyte opened this issue Jul 2, 2023 · 1 comment
Open

Question about @Valide in Todo project #21

sunbyte opened this issue Jul 2, 2023 · 1 comment

Comments

@sunbyte
Copy link

sunbyte commented Jul 2, 2023

Hello!

I have question about spring boot validation in Todo project.

public String addNewTodo(ModelMap modelMap, @Valid Todo todo, BindingResult bindingResult) {...}

If we change the position of the method parameters and put @Valid Todo todo before ModelMap modelMap, the validation not work correct and we don't see the error message in the form, but getting an exceptions in the browser. Why?

Thanks.

@Aayush-Kapur
Copy link

Hey @sunbyte
If you're trying to put @Valid Todo todo before ModelMap modelMap , keep in mind that the BindingResult parameter must immediately follow the @Valid annotated object. Spring MVC uses BindingResult to collect validation errors for the todo object. If it's not positioned correctly after @Valid, Spring may not be able to capture validation errors correctly, leading to unexpected behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants