這是我的這會導致錯誤既不BindingResult也不對bean名稱純目標對象「bankDetails [0]」可作爲請求屬性誤差在Spring MVC
<form:select path="bankDetails[0].applicantType">
<form:option value="Applicant">Applicant</form:option>
<form:option value="Co-Applicant 1">Co-Applicant 1</form:option>
<form:option value="Co-Applicant 2">Co-Applicant 2</form:option>
<form:option value="Co-Applicant 3">Co-Applicant 3</form:option>
<form:option value="Guarantor 1">Guarantor 1</form:option>
<form:option value="Guarantor 2">Guarantor 2</form:option>
<form:option value="Guarantor 3">Guarantor 3</form:option>
</form:select>
這是我的控制器代碼
JSP代碼段@RequestMapping(value = "enterBankDetails.htm", method = RequestMethod.GET)
public ModelAndView enterBankDetails() {
functionName = "enterBankDetails";
logger.info("In "+className+" - "+functionName+" ");
BankDetails details = new BankDetails();
ArrayList<EntityBankDetail> entitityBankDetails = new ArrayList<EntityBankDetail>();
for(int i = 0 ; i < 4 ;i++){
EntityBankDetail entityBankDetail = new EntityBankDetail();
entitityBankDetails.add(entityBankDetail);
}
details.setBankDetails(entitityBankDetails);
return new ModelAndView("bankDetails/bankDetails", "command",details);
}
這裏是bean代碼
public class BankDetails {
private ArrayList<EntityBankDetail> bankDetails;
private String[] entities;
private int noOfBankDetails;
private String test;
//getter and setter methods
}
public class EntityBankDetail {
private String nameOfBank;
private String EMIforProposedLoan;
private String nameOfBranch;
private String city;
private String accountType;
private String accountNumber;
private String applicantType;
//getter and setter methods
}
我收到以下錯誤
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'bankDetails[0]' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
請大家幫忙。我不知道我在做什麼錯誤?
編輯:當我結合它來測試
<form:select path="test">
<form:option value="Applicant">Applicant</form:option>
<form:option value="Co-Applicant 1">Co-Applicant 1</form:option>
<form:option value="Co-Applicant 2">Co-Applicant 2</form:option>
<form:option value="Co-Applicant 3">Co-Applicant 3</form:option>
<form:option value="Guarantor 1">Guarantor 1</form:option>
<form:option value="Guarantor 2">Guarantor 2</form:option>
<form:option value="Guarantor 3">Guarantor 3</form:option>
</form:select>
Neither BindingResult nor plain target object for bean name 'test' available as request attribute
我不必打印出值。我必須綁定每個EntityBankDetail對象的屬性才能形成。 –
我知道,但是您正在以數組的形式訪問bankDetails;不是ArrayList。 – blackpanther
我可以隨時訪問它,我有一個工作代碼,說明了這一點。請檢查我的編輯了。 –