gpt4 book ai didi

spring注释错误找不到类型: java. lang.Double的验证器

转载 作者:行者123 更新时间:2023-12-02 00:07:14 25 4
gpt4 key购买 nike

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

我编写的模型如下

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

最佳答案

注解@NotEmpty支持类型:String、Collection、Map和数组。

您应该使用:

@NotNull
private someProperty;

查看此Validation step by step或者这个:JavaEE bean validation

关于spring注释错误找不到类型: java. lang.Double的验证器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24892469/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com