I am new to spring and I am facing the following issue:
我能夠做一個新的控制器和ModelAndView的方法做出POST調用,但現在我面臨着數據的一個多問題沒有從JSP傳遞到控制器。 我的JSP代碼:
form:form method="POST" action="UserOperation"
modelAttribute="DebitModel">
<h3>Debit</h3>
<c:if test="${!empty listAccounts}">
<select name="item" id="account_dropdown"
onchange="changeAccountDetails(this.options[this.selectedIndex].value)">
<c:forEach items="${listAccounts}" var="account">
<option
value="${account.accID},${account.acctype},${account.balance}">AccID:
${account.accID} Balance: ${account.balance}</option>
</c:forEach>
</select>
<br>
<br>
<label ><b>Account ID: </b></label>
<label id="accIdText" path="accID">${listAccounts[0].accID}</label>
<label><b>Account Type: </b></label>
<label id="accTypeText" path="acctype">${listAccounts[0].acctype}</label>
<label><b>Balance: </b></label>
<label id="accBalText" path="balance">${listAccounts[0].balance}</label>
</c:if>
<br> <br> Enter Amount<input type="text"
id="amount" width="80" path="amount"></input> <br> <br>
<input type="submit" value="Debit"></input>
</form:form>
有一個名爲DebitModel正常的bean類。 我試圖搜索,並在許多地方的數據沒有得到通過,並找到解決方案作爲形式:輸入提到,但如果我使用這個,我沒有得到綁定FoundException'java.lang.IllegalStateException:無論是BindingResult還是普通的目標對象的bean名' DebitModel'作爲請求屬性 '提供,即使存在<%@ taglib uri =「http://www.springframework.org/tags/form」prefix =「form」%>。
The Controller class Code:
@Controller
@RequestMapping(value = "/UserOperation")
public class DebitController {
@Autowired
private AccountService mAccountService;
@RequestMapping(method = RequestMethod.POST)
public ModelAndView registerCustomer(@ModelAttribute("DebitModel") DebitModel debitModel, BindingResult result,
HttpServletRequest request) throws NoSuchAlgorithmException, FileNotFoundException {
ModelAndView modelAndView = new ModelAndView();
System.out.println("data------------------------" + debitModel.toString());
return modelAndView;
}
}
郵報工作的GET方法。 – chrylis
這只是一個建議,你可以嘗試使用(at)RequestBody而不是(at)ModelAttribute。 http://stackoverflow.com/questions/21824012/spring-modelattribute-vs-requestbody。 @ a007 –
顯示你的彈簧mvc配置。 –