表格字段常用注解@NotBlank @NotEmpty @NotNul @Pattern
在Hibernate Validator(org.hibernate.validator.constraints)中:
@NotEmpty://CharSequence, Collection, Map 和 Array 对象不能是 null 并且相关对象的 size 大于 0。
@NotBlank://String 不是 null 且去除两端空白字符后的长度(trimmed length)大于 0。
例子:@NotBlank(message = "城市名不能为空")
在java EE中:
@Pattern(regexp = "^[1-9]\\d?(\\.\\d)?$|^100$|^100\\.0$", message = "当月目标值格式错误,请确保为1到100且不超过一位小数的数字")
只能修饰string类型的字段
@NotNull://CharSequence, Collection, Map 和 Array 对象不能是 null, 但可以是空集(size = 0)。
官方文档:
另一篇博客(http://blog.csdn.net/zz_life/article/details/51470909)比较粗暴的总结:
@NotEmpty 用在集合类上面
@NotBlank 用在String上面
@NotNull 用在基本类型上
本博客文章皆出于学习目的,个人总结或摘抄整理自网络。引用参考部分在文章中都有原文链接,如疏忽未给出请联系本人。另外,作为一名菜鸟程序媛,如文章内容有错误,欢迎点击博客右上方的扣扣链接指导交流。