Skip to content
Advertisement

BindingResult haserror() not working and gives only same answer

I want to write Binding result without JSP file and I wrote like this. But I get same result every time

JavaScript

Advertisement

Answer

Looks like you missed javax.validation.Valid annotation for your request body :

JavaScript

Once you have annotated your method with Valid annotation, your request body will get validated in controller layer & any validation related errors can be seen in your else block of if (!bindingResult.hasErrors()).

Tip : You can also throw org.springframework.web.bind.MethodArgumentNotValidException in absence of BindingResult in your method argument.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement