mirror of
https://github.com/Example-uPagge/spring_boot_docker.git
synced 2024-06-14 11:52:52 +03:00
Group Validation
This commit is contained in:
parent
9799bd7e5c
commit
51f315189a
@ -0,0 +1,33 @@
|
||||
package org.sadtech.example.springvalidation.controller;
|
||||
|
||||
import org.sadtech.example.springvalidation.dto.PersonDto;
|
||||
import org.sadtech.example.springvalidation.valid.Marker;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
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;
|
||||
import javax.validation.groups.Default;
|
||||
|
||||
@Validated
|
||||
@RestController
|
||||
@RequestMapping("/api/group-valid/person")
|
||||
public class PersonControllerGroupValid {
|
||||
|
||||
@PostMapping
|
||||
@Validated({Marker.OnCreate.class})
|
||||
public ResponseEntity<String> create(@RequestBody @Valid PersonDto personDto) {
|
||||
return ResponseEntity.ok("valid");
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Validated(Marker.OnUpdate.class)
|
||||
public ResponseEntity<String> update(@RequestBody @Valid PersonDto personDto) {
|
||||
return ResponseEntity.ok("valid");
|
||||
}
|
||||
|
||||
}
|
@ -3,6 +3,7 @@ package org.sadtech.example.springvalidation.dto;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.sadtech.example.springvalidation.valid.CapitalLetter;
|
||||
import org.sadtech.example.springvalidation.valid.Marker;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
@ -10,10 +11,11 @@ import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Null;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
@Entity
|
||||
@ -23,6 +25,8 @@ import javax.validation.constraints.Pattern;
|
||||
public class PersonDto {
|
||||
|
||||
@Id
|
||||
@Null(groups = Marker.OnCreate.class)
|
||||
@NotNull(groups = Marker.OnUpdate.class)
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
package org.sadtech.example.springvalidation.valid;
|
||||
|
||||
public interface Marker {
|
||||
|
||||
interface OnCreate {}
|
||||
|
||||
interface OnUpdate {}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user