今天做项目遇到一个问题
public class Cart {
private Mapmap = new LinkedHashMap();
/*******************************
省略若干方法
*******************************/
/**
* 购物车内总价(二进制运算问题)
* @return
*/
public double getTotal() {
BigDecimal total = new BigDecimal(0);
for(CartItem cartItem : map.values()) {
BigDecimal subtotal = new BigDecimal(cartItem.getSubtotal());
total = total.add(subtotal);//购物车内总价就是所有条目的价钱之和
}
return total.doubleValue();
}
public CollectiongetCartItems(){
return map.values();
}
}
然后在jsp中EL表达式想获取CartItems和Total属性时报错
org.apache.jasper.el.JspPropertyNotFoundException: /jsps/cart/list.jsp(74,0) '${sessionScope.cart.CartItems }' Property [CartItems] not found on type [com.****.*****.domain.Cart]
很显然,是说找不到这个属性。
查找完资料发现将
属性首字母改成小写-->即a.name 等于a.getName();
后就可以找到了
所以要用到EL表达式的属性 命名要 规范啊!! 最好全小写了!!