我得到一個錯誤:無效的屬性bean類的 'redeemVoucherForm'[my.testapp.forms.RedeemVoucherForm]
Invalid property 'redeemVoucherForm' of bean class [my.testapp.forms.RedeemVoucherForm]: Bean property 'redeemVoucherForm' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
RedeemVoucherForm.java:
package my.testapp.forms;
public class RedeemVoucherForm {
private String voucherCode;
public String getVoucherCode() {
return voucherCode;
}
public void setVoucherCode(String voucherCode) {
this.voucherCode = voucherCode;
}
}
在我PageController.java
,我當我調用方法model.containsAttribute(「redeemVoucherForm」)時,存在添加模型redeemVoucherForm
:
@RequestMapping(method = RequestMethod.GET)
public String showPage(final Model model) {
...
model.addAttribute("redeemVoucherForm", new RedeemVoucherForm());
...
return REDIRECT_PAGE_URL;
}
@RequestMapping(value = "/redeem-voucher", method = RequestMethod.POST)
public String redeemVoucher(@Valid final RedeemVoucherForm redeemVoucherForm, final BindingResult bindingResult, final RedirectAttributes redirectModel, final Model model, HttpServletRequest request) {
LOG.debug("<POST> Redeeming voucher...");
return REDIRECT_PAGE_URL;
}
pageDisplay.jsp:
<c:url value="/page/redeem-voucher" var="redeemVoucherAction" />
<form:form action="${redeemVoucherAction}" method="post" commandName="redeemVoucherForm">
<form:input cssClass="form-control" type="text" path="redeemVoucherForm.voucherCode"/>
<button type="submit" class="btn btn-primary btn-block checkoutButton">
<spring:theme text="Redeem Voucher"/>
</button>
</form:form>
我還有什麼可會丟失,當我已經設置模式redeemVoucherForm
?
'redeemCode'?這必須在你的代碼中,但它不會出現在你發佈的代碼中的任何地方。 –
我的不好,我再次輸入錯誤。我寫了redeemCode而不是voucherCode。一切都好。非常感謝你! – Kapparino