46. Custom Bean Validation Annotation in Spring

  Рет қаралды 23,260

Miss Xing (邢老师)

Miss Xing (邢老师)

Күн бұрын

Пікірлер: 44
@mr.techno-era7474
@mr.techno-era7474 4 жыл бұрын
I'm searching for this for 4 days. Great video
@soccypowa
@soccypowa 2 жыл бұрын
谢谢, exactly the type of validator, almost, I was looking for, and with the explanation everything was clear as a day, thanks Miss Xing!
@Milt17p
@Milt17p 4 жыл бұрын
One of the best tutorials I've seen. Thank you!
@flopani5059
@flopani5059 3 жыл бұрын
This was very explanatory and it worked from the first try on my own custom validation!
@nazmulhassanmd3222
@nazmulhassanmd3222 2 жыл бұрын
Thank you so much …. I have learned a lot from this video
@laogedj
@laogedj 3 жыл бұрын
Great video, easy to understand, thank you Xing
@hitterobr
@hitterobr 3 жыл бұрын
You saved my life, thank's
@alouiachref9932
@alouiachref9932 3 жыл бұрын
Big love and thank you , you are the best
@ametsoro5580
@ametsoro5580 3 жыл бұрын
Really enjoy this tutorial thanks !!!
@cornelliushatcher
@cornelliushatcher 2 жыл бұрын
Very useful stuff, thanks for uploading.., any idea how List can be validated using hibernate validator?
@elmarvo7505
@elmarvo7505 Жыл бұрын
Hello, thank you for the video! Can you or someone else please explain the lines 15 and 16 in class Age? Class[] groups() default {}; and the Payload thing? What does it do and why do I need it? Thank you
@krige
@krige 3 жыл бұрын
Great video, thanks! It would be very nice if you would share the source of your knowledge in the video description. I would name the class "AgeValidator" instead of "AgeValidation".
@amitdubey6867
@amitdubey6867 3 жыл бұрын
not getting error messages displayed on jsp while validation is working.. any help. thank you.
@AliHassan-ty2me
@AliHassan-ty2me Жыл бұрын
same issue do you configure this out ?
@EduardoSilva-us1jp
@EduardoSilva-us1jp 3 жыл бұрын
Great, thanks. I have a question. I need to validate a field but I need to access the database to do so. I'd like to know whether it's better to have this validation in the DTO which has an id for the validation class to use to access the database, or in the DAO layer which doesn't have the id but the entity itself, for now, it's in the DTO.
@EduardoSilva-us1jp
@EduardoSilva-us1jp 3 жыл бұрын
For ex: // Given from the Dto isValid(Long id, Ctx...){ repository.findbyId(id) ... Processing validation } // Given from DAO isValid(Entity x, ctx...){ repository.findById(x.getId()); // Process }
@Vlfkfnejisjejrjtjrie
@Vlfkfnejisjejrjtjrie 3 жыл бұрын
@@EduardoSilva-us1jp your DTO should be bare bones and only pass data, it shouldn't be calling the repo.findby. Pass the data to your entity and let it do the work. DTO ->Service->Entity-> Repo. You could use a request DTO and Response DTO to transfer data to/from Service. The service will be referenced from calling Controller.
@shuuheihisagi3148
@shuuheihisagi3148 3 жыл бұрын
@@Vlfkfnejisjejrjtjriehey, thanks. What was actually calling repo.findby was the class implementing ConstraintValidator, by annotating the dto, its field (dto field) which was an integer was being sent to the validator class so it would use the id and the repo.findby. When annotating the actual object, the validator was getting the current object field
@shuuheihisagi3148
@shuuheihisagi3148 3 жыл бұрын
My dto would only contain both lombok and validation annotations provided by starter validation and annotations created just like in the video, is that ok?
@Vlfkfnejisjejrjtjrie
@Vlfkfnejisjejrjtjrie 3 жыл бұрын
@@shuuheihisagi3148 anything is okay, depending on your needs. Using lombok is common, but I wouldn't call validation fro a DTO. It's commonly used as a convenience mechanism to move groups of data from one p,ace to another.
@naveenkumar-vf6pk
@naveenkumar-vf6pk 3 жыл бұрын
hi if we want supply the annotation to class level and field level as well as method level then how can we configure in customvalidator
@worchock
@worchock 3 жыл бұрын
thanks, greeting from colombia
@krige
@krige 3 жыл бұрын
Is it possible to print the value being invalidated in the constraint annotation String message() default?
@helanomiguel3783
@helanomiguel3783 4 жыл бұрын
One thing that is not clear to me is how can I access the validation message using a Java code? I thought that the Annotation API would throw a new ValidationExcepion, but i did not happen that way
@vdm2002
@vdm2002 3 жыл бұрын
What about the explanation for the Initialize method?
@ashwinikumar9138
@ashwinikumar9138 4 жыл бұрын
How to create custom annotation to return string padding
@somnathchaudhuri28222
@somnathchaudhuri28222 4 жыл бұрын
I have written two validation logic in isValid method and want to display different single message based on my if else condition . Can u tell me how to do that.
@MissXing
@MissXing 4 жыл бұрын
You need to explain more, the if/else condition is based on what? When we add custom annotation, we only have 1 class to perform checking. So only 1 isValid() being called for 1 annotation. So if based on the value, just add if/else in isValid(). If not based on the value, I don't know which condition you're mentioning here.
@Jeptxxle
@Jeptxxle 4 жыл бұрын
How can I set the message depending on users locale?
@manikolla3437
@manikolla3437 4 жыл бұрын
hi miss xing that was wonderful explaination have given about the custom bean validation but i have one question what is difference java bean validation and spring bean validation(i mean spring has release newer version of validator interface) ?
@MissXing
@MissXing 4 жыл бұрын
Two different ways to implement bean validation. Jave doesn't have bean implementation of validator. Hibernate validator is the implementation of bean validation specification. Spring can integrate with it. The other way is you use spring validator interface without using Hibernate validator implementation.
@vishnugovindan8550
@vishnugovindan8550 4 жыл бұрын
Is there anyway to get the particular class level bean validation error messages so that we can display it next to the age input box (rather than being binded to ) ??
@vishnugovindan8550
@vishnugovindan8550 4 жыл бұрын
I think I have figured it out You have to map this constraint violation to the required field to that it can get picked up by @Override public boolean isValid(User user, ConstraintValidatorContext context) { if(user.getAge() != null) { Period period = Period.between(user.getBirthday(),LocalDate.now()); context.buildConstraintViolationWithTemplate(errorMessage).addPropertyNode("age").addConstraintViolation(); return user.getAge() == period.getYears(); } return false; }
@МаксимБочковВолодимирович
@МаксимБочковВолодимирович 4 жыл бұрын
Thank you!
@AboiGaming
@AboiGaming 3 жыл бұрын
Great Work
@saddammd
@saddammd 4 жыл бұрын
Nice explanation
@prabhatgaur1150
@prabhatgaur1150 4 жыл бұрын
How to validate list of user
@MissXing
@MissXing 4 жыл бұрын
This is an interesting question. if use a form, how can you add a collection of user, what's the data binding look like? You must have another wrapper object in order to submit collection, if in this case, a collection will be validated one by one.
@prabhatgaur1150
@prabhatgaur1150 4 жыл бұрын
I've written my custom constraints in user method resultValidations() I don't like validation framework. Stream can filter collection in one line
@grape__07
@grape__07 6 ай бұрын
thx
@saddammd
@saddammd 4 жыл бұрын
Nice explanation
47. Interceptor in Spring MVC
11:57
Miss Xing (邢老师)
Рет қаралды 3,4 М.
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН
Мен атып көрмегенмін ! | Qalam | 5 серия
25:41
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН
Cat mode and a glass of water #family #humor #fun
00:22
Kotiki_Z
Рет қаралды 42 МЛН
Spring Boot Custom Validation Annotation (with parameters)
16:39
Spring MVC - 10. Validation
11:46
Teddy Smith
Рет қаралды 10 М.
My 10 “Clean” Code Principles (Start These Now)
15:12
Conner Ardman
Рет қаралды 315 М.
Spring Boot Rest API Validation with Hibernate Validator
15:33
Java Guides
Рет қаралды 33 М.
Java Annotations #2 - Create your own custom Java Annotations
17:57
Spring Boot - JSR 303 - The Right Way To Validate Objects
43:41
Bouali Ali
Рет қаралды 23 М.
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН