欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringBoot @NotBlank錯誤的解決方案

 更新時間:2021年08月06日 14:30:11   作者:Msr 王  
這篇文章主要介紹了SpringBoot @NotBlank錯誤的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

SpringBoot @NotBlank錯誤

java 驗證出現(xiàn)如下錯誤:

javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint

錯誤原因

Java實體類中屬性是Integer類型,用了NotBlank判斷不能為空,而這個注解是判斷字符串是否為空

解決辦法

去掉@NotBlank注解、使用@NotNull

@NotBlank注解地正確使用

@NotNull:不能為null,但可以為empty

@NotEmpty:不能為null,而且長度必須大于0

@NotBlank:只能作用在String上,不能為null,而且調(diào)用trim()后,長度必須大于0

案例

String name = null;@NotNull: false@NotEmpty:false @NotBlank:false 2.String name = "";@NotNull:true
@NotEmpty: false@NotBlank: false3.String name = " ";@NotNull: true
@NotEmpty: true@NotBlank: false4.String name = "Great answer!";@NotNull: true@NotEmpty:true@NotBlank:true

注意在使用@NotBlank等注解時,一定要和@valid一起使用,不然@NotBlank不起作用

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論