validator验证:
@Email:验证邮箱格式
@Length:Validate that the string is between min and max included.:
实例:
@Length(min = 1, max = 100, message = “application_detail length limit from 1 to 100”)
private String applicationDetail;
@NotBlank:Validate that the annotated string is not null or empty. The difference to NotEmpty is that trailing whitespaces are getting ignored.
@NotNull:The annotated element must not be null. Accepts any type
@Size(max=, min=) The annotated element size must be between the specified boundaries (included).
例如:
@NotEmpty:Asserts that the annotated string, collection, map or array is not null or empty.
@NotEmpty(groups = {Approval.class}, message = “approver_account is empty”)
private String approverName;
三者使用总结:当为Byte或者Long 类型参数验证时,使用@NotNull
@Size(min = 1, max = 10, message = “Posting 1 to 10 approver_candidate at a time is allowed”)
private List approverCandidate;
@Pattern(regex=,flag=) 被注释的元素必须符合指定的正则表达式
只能匹配字符串。
问题:
1、前端传来json的列表时,可以直接使用list类型接收,可自动转化为列表。
2、使用byte,long等基本类型,作为DTO传送数据时,未赋值,会自动赋值0.而不是保持null;
知识点:基本类型和引用类型的赋值机制。
3、接收前端json数据时,基本类型要使用对应的包装类型,否则会报错。
常见validator使用与前后端传送数据问题
最新推荐文章于 2022-09-07 23:45:53 发布