gpt4 book ai didi

java - 如何在 Spring 中将 AutopopulatedList 引用到 List

转载 作者:太空宇宙 更新时间:2023-11-04 10:52:02 28 4
gpt4 key购买 nike

我正在尝试使用 AutoPopulateList 创建动态填充列表。我还有一个表单对象,如下面的代码所示:

public class CDNoteForm{

private AbstractCDNote cdnote;
private List<? extends AbstractInvoiceItem> invoiceItemList ;


public CDNoteForm() {
super();
}
public CDNoteForm(String type){
super();
if(type.equals("cdnote")){
this.invoiceItemList = new AutoPopulatingList<CDNoteItem>(CDNoteItem.class);
}
else if(type.equals("vendorcdnote")) {
this.invoiceItemList = new AutoPopulatingList<VendorCDNoteItem>(VendorCDNoteItem.class);
}

}

public AbstractCDNote getCdnote() {
return cdnote;
}
public void setCdnote(AbstractCDNote cdnote) {
this.cdnote = cdnote;
}
public List<? extends AbstractInvoiceItem> getInvoiceItemList() {
return invoiceItemList;
}
public void setInvoiceItemList(List<? extends AbstractInvoiceItem> invoiceItemList) {
this.invoiceItemList = invoiceItemList;
}
}

表单对象正在我的 Controller 中的方法中声明,如下所示。

@RequestMapping(value ="/cdnote/create"  , method = RequestMethod.GET)
public String getCreateCDNotePage(Model model){

CDNoteForm cdnoteForm = new CDNoteForm("cdnote");
model.addAttribute("CDNoteForm" , cdnoteForm);
return "AddCDNote";
}

“invoiceItemList”在 jsp 中被引用,如下所示

<form:input type="text" id="Quantity0"  path="invoiceItemList[0].quantity" class="form-control"></form:input>                       

两个类“CDNoteItem”和“VendorCDNoteItem”扩展了抽象类“AbstractInvoiceItem”。现在我在编译时没有收到任何错误,但是当我尝试运行它并访问该页面时,我在控制台上收到以下错误。

SEVERE: Servlet.service() for servlet [SpringGST] in context with path [/SpringGST] threw exception [org.springframework.beans.InvalidPropertyException: Invalid property 'invoiceItemList[0]' of bean class [com.gst.FormObjects.CDNoteForm]: Illegal attempt to get property 'invoiceItemList' threw exception; nested exception is org.springframework.beans.NullValueInNestedPathException: Invalid property 'invoiceItemList' of bean class [com.gst.FormObjects.CDNoteForm]: Could not instantiate property type [com.gst.models.AbstractInvoiceItem] to auto-grow nested property path: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.gst.models.AbstractInvoiceItem]: Is it an abstract class?; nested exception is java.lang.InstantiationException] with root cause
org.springframework.beans.NullValueInNestedPathException: Invalid property 'invoiceItemList' of bean class [com.gst.FormObjects.CDNoteForm]: Could not instantiate property type [com.gst.models.AbstractInvoiceItem] to auto-grow nested property path: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.gst.models.AbstractInvoiceItem]: Is it an abstract class?; nested exception is java.lang.InstantiationException

我不明白为什么当“invoiceItemlist”引用其子类的自动填充列表进行初始化时,它试图实例化抽象类“AbstractInvoiceItem”

最佳答案

你可以使用invoiceItemList.get(0)代替invoiceItemList[0]并尝试

关于java - 如何在 Spring 中将 AutopopulatedList<ChildClass> 引用到 List<AbstractBaseClass> ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47711853/

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