In my controller I have a method for creating an entity
import javax.validation.Valid;
...
@RestController
public class Controller {
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<?> create(@Valid @RequestBody RequestDTO requestDTO) {
...
with
import org.hibernate.validator.constraints.NotEmpty;
...
public class RequestDTO
@NotEmpty // (1)
private String field1;
//other fields, getters and setters.
I want to add a controller method
update(@Valid @RequestBody RequestDTO requestDTO)
but in this method it should be allowed for field1
to be empty or null, i.e. the line
@NotEmpty // (1)
of the RequestDTO
should be ignored.
How can I do this? Do I have to write a class that looks exactly the same like RequestDTO
, but does not have the annotation? Or is it somehow possible via inheritance?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…