: It defines at what point the annotation should be discarded. The first step is to define our Annotation with : This is the annotation where we provide the class which will validate our field. ![]() We will validate customerId and phoneNumber by making our custom validations. Here we have defined 3 fields which are name, customerId, and phoneNumber. Setup a Spring Boot Java 8 project using Spring Initializer.įor this example, we will build a simple application that will provide us with an endpoint to POST data.In this blog, we will have a look at how we can add custom validations with the help of an example. In cases like these, we need to build our custom validations. For example: when we need to validate a field that should only expect a 10 digit phone number. ![]() Spring makes our lives easier by providing us with some built-in validations like: This will not create a problem if validations are applied as the application can return invalid requests and may ask the user to provide correct fields, but in the absence of validations, it is sure to cause problems in some instances, as it may process incorrect data and disrupt the flow. There are many times the data received may get corrupted before reaching the application or the user may provide wrong inputs. It is crucial to have control over the data that the application interacts with to ensure it behaves as expected. While building applications and services it is very important that we maintain data integrity especially if they are data-centric.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |