spring annotation error找不到类型为:java.lang.Double的验证器

时间:2014-07-22 16:10:46

标签: spring annotations

我正在使用spring 3.1和annotations开发应用程序。

我写的模型如下

package servlet.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.validator.constraints.NotEmpty;
@Entity
@Table(name="products")
public class Product {
 @Id
 @GeneratedValue
 private Integer product_id;
 @NotEmpty(message = "Category should not be blank.")
 private String cat_id;
 @NotEmpty(message = "Name should not be blank.")
 private String product_name;

 private String specification;
 @NotEmpty(message = "Purchase Price should not be blank.")
 private double purchase_price;
 @NotEmpty(message = "Sales Price should not be blank.")
 private double sales_price;
 @NotEmpty(message = "Stock should not be blank.")
 private double stock;
 @NotEmpty(message = "Status should not be blank.")
 private String status;

 @Column(name="product_id")
 public Integer getProduct_id() {
    return product_id;
 }
 public void setProduct_id(Integer product_id) {
  this.product_id = product_id;
 }

 @Column(name="cat_id")
 public String getCat_id() {
    return cat_id;
 }
 public void setCat_id(String cat_id) {
  this.cat_id = cat_id;
 }

 @Column(name="product_name")
 public String getProduct_name() {
  return product_name;
 }
 public void setProduct_name(String product_name) {
    this.product_name = product_name;
 }

 @Column(name="specification")
 public String getSpecification() {
    return specification;
 }
 public void setSpecification(String specification) {
    this.specification = specification;
 }

 @Column(name="purchase_price")
    public double getPurchase_price() {
 return purchase_price;
 }
 public void setPurchase_price(double purchase_price) {
 this.purchase_price = purchase_price;
 }

 @Column(name="sales_price")
    public double getSales_price() {
 return sales_price;
 }
 public void setSales_price(double sales_price) {
  this.sales_price = sales_price;
 }

 @Column(name="stock")
 public double getStock() {
    return stock;
 }
 public void setStock(double stock) {
    this.stock = stock;
 }

 @Column(name="status")
 public String getStatus() {
 return status;
 }
 public void setStatus(String status) {
 this.status = status;
 }

}

在提交表单时,我收到请求处理失败;嵌套异常是javax.validation.UnexpectedTypeException:找不到类型的验证程序:java.lang.Double

1 个答案:

答案 0 :(得分:5)

注释@NotEmpty支持类型:字符串,集合,映射和数组。你可以试试@NotNull注释。或另一个anotation

请参阅此Validation step by step