开发者社区 问答 正文

Jfinal类中类取值问题?报错

@JFinal 你好,想跟你请教个问题:

Jsp中为什么取不到值?

报错:

 Servlet.service() for servlet jsp threw exception
javax.el.PropertyNotFoundException: Property 'pictName' not found on type com.demo.gallery.Gallery

这个Gallery类  extends Model<Gallery>,后台中有pictName这个字段呀.为什么取不到呢?

代码如下:

public void  carShopList(){
		CartBiz  cb=(CartBiz) getSession().getAttribute("shopCart");
		if (cb!=null){
			List<CarItem>  list=cb.getCarItems();
			System.out.println("------CarList------");
			for (CarItem carItem : list) {
				System.out.println(carItem.getGallery().getStr("pictName"));
			}
			setAttr("carList", list)  ;   
		}
			render("cartShop.jsp");
	}



package com.demo.car;
import java.math.BigDecimal;
import com.demo.gallery.Gallery;

public class CarItem {
	private Gallery  gallery;
	private Integer qty;
	private BigDecimal  totalPrice;
	
	public CarItem(Gallery  gallery,Integer qty){
	   super();
       this.gallery=gallery;
       this.qty=qty;
	}
	
	
	public Gallery getGallery() {
		return gallery;
	}
	public void setGallery(Gallery gallery) {
		this.gallery = gallery;
	}
	public Integer getQty() {
		return qty;
	}
	public void setQty(Integer qty) {
		this.qty = qty;
	}
	public BigDecimal  getTotalPrice() {
	   BigDecimal bdQty=new BigDecimal(this.qty);
	   BigDecimal bdPrice=this.gallery.getBigDecimal("price"); 
	   
	   this.totalPrice= bdQty.multiply(bdPrice);
	   return totalPrice; 
	}
	
	public BigDecimal getPrice(){
		return this.gallery.getBigDecimal("price");
	}
	

}



public class Gallery extends Model<Gallery> {
  public static final  Gallery dao=new Gallery();
  
}



JSP页面代码:

 
<c:forEach items="${carList}" var="carItem">
<td>
 <a class="fdImg"
 src="upload/${carItem.gallery.pictName}"
 style="width: 50px; height: 50px;" alt="" /> </a>
 </td></c:forEach>


展开
收起
爱吃鱼的程序员 2020-06-22 11:40:29 489 分享 版权
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    jspRender对 CarItem对象没有转换处理,直接返回本身,导致carItem里面的对象不再转换。

    privateObjecthandleObject(Objectvalue,intdepth){if(value==null||(depth--)<=0)returnvalue;if(valueinstanceofList)returnhandleList((List)value,depth);elseif(valueinstanceofModel)returnhandleMap(CPI.getAttrs((Model)value),depth);elseif(valueinstanceofRecord)returnhandleMap(((Record)value).getColumns(),depth);elseif(valueinstanceofMap)returnhandleMap((Map)value,depth);elseif(valueinstanceofPage)returnhandlePage((Page)value,depth);elseif(valueinstanceofObject[])returnhandleArray((Object[])value,depth);elsereturnvalue;}



    解决:

    CarItem继承Model,或 Gallery加get方法。或用freemarker、beetl等模板解析。

    没错是这样的,当时打算同时也支持非Model继承类的,一直没时间希望在新版中增加此功能,希望jfinal越來越好。

    引用来自“andying”的答案

    希望在新版中增加此功能,希望jfinal越來越好。坐等新版出现

    引用来自“JFinal”的答案

    引用来自“andying”的答案

    希望在新版中增加此功能,希望jfinal越來越好。jfinal1.6还不会加入此功能,待加的功能太多了,一步步来^_^
    2020-06-22 11:40:47
    赞同 展开评论
问答分类:
问答标签:
问答地址: