-
Notifications
You must be signed in to change notification settings - Fork 0
5_Валидация, Интернационализация #4
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
base: main
Are you sure you want to change the base?
Conversation
| implementation("org.springframework.boot:spring-boot-starter") | ||
| implementation("org.springframework.boot:spring-boot-starter-web") | ||
| implementation("org.springframework.boot:spring-boot-starter-validation") | ||
| implementation("org.projectlombok:lombok:1.18.30") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compileOnly
| @Service | ||
| @Validated | ||
| public class ArticleService { | ||
| public String create(@Valid ArticleIn article) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вообще такой подход имеет место (использовать аннотации валидации на уровне сервиса) и как правило применяется не к самому сервису, а к его интерфейсу. Но все же, на будущее, следует валидации выполнять на уровне контроллера. Как правило во всех проектах у тебя должны быть обработчики и на MethodArgumentNotValidException, и на ConstraintViolationException
|
|
||
| @PostMapping("/create") | ||
| @ResponseStatus(HttpStatus.CREATED) | ||
| public String register(@RequestBody ArticleIn article) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Возвращать следует ДТО
| import org.javaspringcourse.validation.Title; | ||
|
|
||
| @Data | ||
| public class ArticleIn { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Начиная с java 17 для дто следует использовать record, когда это возможно. Или хотя бы использовать @Value из lombok вместо @Data, т.к. дто должны быть неизменяемыми
Студент: Аптуликсанов Руслан Германович.
Преподаватель: Никита Иванов
RussianFullName,RussianFullNameConstraintValidatorиArticleExceptionHandler)Title)