@Valid和@NotBlank的弹簧启动验证注释不起作用
2022-09-01 02:13:49
下面给出的是我的主控制器,我从中调用getPDFDetails方法。
@RequestMapping(value=PATH_PRINT_CONTRACTS, method=RequestMethod.POST)
public ResponseEntity<?> printContracts(@RequestBody final UpdatePrintContracts updatePrintContracts) throws Exception {
System.out.println("contracts value is "+ updatePrintContracts);
Integer cancellationReasons = service.getPDFDetails(updatePrintContracts);
System.out.println("success!");
return ResponseEntity.ok(cancellationReasons);
}
下面是 UpdatePrintContracts 类,我在其中定义了所有带有验证注释和相应 getter/setter 方法的变量。
public class UpdatePrintContracts {
@Valid
@NotBlank
@Pattern(regexp = "\\p{Alnum}{1,30}")
String isReprint;
@Valid
@NotBlank
Integer dealerId;
@Valid
@NotBlank
@Pattern(regexp = "\\p{Alnum}{1,30}")
String includeSignatureCoordinates;
@Valid
@NotBlank
java.util.List<Integer> contractNumbers;
public String getIsReprint() {
return isReprint;
}
public void setIsReprint(String isReprint) {
this.isReprint = isReprint;
}
public Integer getDealerId() {
return dealerId;
}
public void setDealerId(Integer dealerId) {
this.dealerId = dealerId;
}
public String getIncludeSignatureCoordinates() {
return includeSignatureCoordinates;
}
public void setIncludeSignatureCoordinates(String includeSignatureCoordinates) {
this.includeSignatureCoordinates = includeSignatureCoordinates;
}
public java.util.List<Integer> getContractNumbers() {
return contractNumbers;
}
public void setContractNumbers(java.util.List<Integer> contractNumbers) {
this.contractNumbers = contractNumbers;
}
}
我正在尝试通过右键单击项目(运行方式)并通过Soap UI传递变量的空白值来将应用程序作为Spring Boot应用程序运行。但是,验证似乎不起作用,并且不会在 Soap UI 中引发任何验证错误。我错过了什么?任何帮助是值得赞赏的!