mirror of
https://github.com/Example-uPagge/spring_boot_docker.git
synced 2024-06-14 11:52:52 +03:00
valid body controller
This commit is contained in:
parent
04112db62c
commit
a6c000c1cf
16
pom.xml
16
pom.xml
@ -20,13 +20,19 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.validation</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>validation-api</artifactId>
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.swagger.core.v3</groupId>
|
||||||
|
<artifactId>swagger-annotations</artifactId>
|
||||||
|
<version>2.1.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.springdoc</groupId>
|
||||||
<artifactId>hibernate-validator</artifactId>
|
<artifactId>springdoc-openapi-ui</artifactId>
|
||||||
<version>7.0.0.Final</version>
|
<version>1.5.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
package org.sadtech.example.springvalidation.controller;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.sadtech.example.springvalidation.dto.PersonDto;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/person")
|
||||||
|
@Tag(name = "Пользователи системы")
|
||||||
|
public class PersonController {
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
@Operation(summary = "Валидация на уровне контроллера")
|
||||||
|
public ResponseEntity<String> valid(@Valid @RequestBody PersonDto personDto) {
|
||||||
|
return ResponseEntity.ok("valid");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package org.sadtech.example.springvalidation.dto;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Max;
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.Pattern;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class PersonDto {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Min(1)
|
||||||
|
@Max(10)
|
||||||
|
private int numberBetweenOneAndTen;
|
||||||
|
|
||||||
|
@Pattern(regexp = "^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\\.(?!$)|$)){4}$")
|
||||||
|
private String ipAddress;
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user