例如:
package com.aaa.maven.entity; import org.hibernate.validator.constraints.NotBlank; import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; import java.util.Date; public class Book { private Integer id; @NotBlank(message = "用户名不能为空") private String bname; @Pattern(regexp = "^([0-9]){1,5}$",message = "必须是数字",flags = Pattern.Flag.CASE_INSENSITIVE) private String price; @NotBlank @Size(min = 4,max = 20,message = "请输入4-20之间的字符串") private String publish; private Date bdate; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getBname() { return bname; } public void setBname(String bname) { this.bname = bname; } public String getPrice() { return price; } public void setPrice(String price) { this.price = price; } public String getPublish() { return publish; } public void setPublish(String publish) { this.publish = publish; } public Date getBdate() { return bdate; } public void setBdate(Date bdate) { this.bdate = bdate; } }