@JFinal 你好,想跟你请教个问题:
我在做一个购物车测试功能,小计金额时报错如下:
java.math.BigDecimal cannot be cast to java.lang.Float
数据后台的表price字段的类型如下:
Name Type Length Decimals
price decimal 10 2
qty的int型与price中的Float型相乖报错,应如何解决?,thks.
public class Gallery extends Model {
public static final Gallery dao=new Gallery();
}
package com.demo.car;
import com.demo.gallery.Gallery;
public class CarItem {
private Gallery gallery;
private int qty;
private float totalPrice;
public CarItem(Gallery gallery,int qty){
super();
this.gallery=gallery;
this.qty=qty;
}
public Gallery getGallery() {
return gallery;
}
public void setGallery(Gallery gallery) {
this.gallery = gallery;
}
public int getQty() {
return qty;
}
public void setQty(int qty) {
this.qty = qty;
}
public float getTotalPrice() {
this.totalPrice=this.qty*this.gallery.getFloat("price"); // 此处报错
return totalPrice;
}
public Float getPrice(){
return this.gallery.getFloat("price");
}
}