我不是JSTL和表達式語言方面的專家,所以我的問題可能是愚蠢的......表達式語言和接口
我與Spring MVC和我的控制器工作,我有:
@ModelAttribute("export_types")
public ExportType[] getExportTypes() {
return edService.getTypes();
}
ExportType
是一個自定義接口:
public interface ExportType {
String getName();
//...
}
在我的網頁我有:
<c:forEach var="item" items="${export_types}">
<tr>
<td><input type="checkbox" value="${item.name}"></td>
<td>${item.name}</td>
</tr>
</c:forEach>
但是當我跑我的web應用程序我得到這個厚望:javax.el.PropertyNotFoundException: Property 'name' not found on type java.lang.String
奇怪的是,除了說on type java.lang.String
而不是在ExportType
類型。所以我的問題是:不能使用接口的表達式語言嗎?
注1
edService.getTypes()
返回一個ExportType[]
陣列與所述接口的具體實現。
爲了清楚起見,我有一個抽象類,實現了ExportType
接口。具體類型從這個繼承:
public abstract class AbstractExportType implements ExportType {
protected String name;
protected AbstractExportType() {
this.name = this.getClass().getSimpleName();
}
@Override
String getName(){
return this.name;
}
//...
}
注2:
轉發到export.jsp控制器的方法很簡單:
'edService.getTypes();'這是什麼確切返回? –
@JigarJoshi看注意 – davioooh
確保你不會覆蓋'export_types'屬性的某處。 – axtavt