|
|
@@ -491,7 +491,7 @@ public ResponseEntity<?> handleResourceNotFoundException(ResourceNotFoundExcepti
|
|
491
|
491
|
|
|
492
|
492
|
|
|
493
|
493
|
|
|
494
|
|
-## Part 5.4 - Validating domain entities
|
|
|
494
|
+## Part 5.5 - Validating domain entities
|
|
495
|
495
|
|
|
496
|
496
|
Now it's time to make sure that all objects persisted to the database actually contain valid values. Use the `org.hibernate.validator.constraints.NotEmpty` and `javax.validation.constraints.Size` and `javax.validation.Valid` annotations for validation.
|
|
497
|
497
|
|
|
|
@@ -500,7 +500,7 @@ Now it's time to make sure that all objects persisted to the database actually c
|
|
500
|
500
|
- `question` should be `@NotEmpty`
|
|
501
|
501
|
- To enforce these validations, add `@Valid` annotations to Poll objects in `RequestMapping`-annotated controller methods (there should be 2)
|
|
502
|
502
|
|
|
503
|
|
-## Part 5.5 - Customizing validation errors
|
|
|
503
|
+## Part 5.6 - Customizing validation errors
|
|
504
|
504
|
|
|
505
|
505
|
In order to customize validation errors we'll need a class for error information. Create a `ValidationError` class in `io.zipcoder.tc_spring_poll_application.dto.error` with the following fields and appropriate getters and setters:
|
|
506
|
506
|
|
|
|
@@ -510,7 +510,7 @@ In order to customize validation errors we'll need a class for error information
|
|
510
|
510
|
We also need a new field in the `ErrorDetail` class to hold errors. There may be multiple validation errors associated with a request, sometimes more than one of the same type, so this field will be a collection, specifically a `Map<String, List<ValidationError>> errors` field.
|
|
511
|
511
|
|
|
512
|
512
|
|
|
513
|
|
-## Part 5.6 - Create a validation error handler
|
|
|
513
|
+## Part 5.7 - Create a validation error handler
|
|
514
|
514
|
|
|
515
|
515
|
- add below handler to `RestExceptionHandler`
|
|
516
|
516
|
|
|
|
@@ -544,7 +544,7 @@ for(FieldError fe : fieldErrors) {
|
|
544
|
544
|
}
|
|
545
|
545
|
```
|
|
546
|
546
|
|
|
547
|
|
-## Part 5.7 - Externalize strings in a messages.properties file
|
|
|
547
|
+## Part 5.8 - Externalize strings in a messages.properties file
|
|
548
|
548
|
|
|
549
|
549
|
Commonly used strings in your Java program can be removed from the source code and placed in a separate file. This is called externalizing, and is useful for allowing changes to text displayed without impacting actual program logic. One example of where this is done is in internationalization, the practice of providing multilingual support in an application, allowing users to use an application in their native language.
|
|
550
|
550
|
|