gpt4 book ai didi

java - Spring绑定(bind)jsp问题

转载 作者:行者123 更新时间:2023-11-30 08:16:38 25 4
gpt4 key购买 nike

当点击如下所示的 Controller 方法时,我总是得到 500。

@RequestMapping(value ="transferInvoiceHdrForm", method = RequestMethod.GET)
protected ModelAndView showForm(@ModelAttribute("transferInvoice") TransferInvoiceForm trinvoiceform, final HttpServletRequest request, final HttpServletResponse response, Model model)throws Exception {
TransferInvoiceHdr transferInvoiceHdr = new TransferInvoiceHdr();
List<TransferInvoice> transferinvoice= transferInvoiceHdrService.getAssetCategoriesandTransfer();
List<Employees> employees = transferInvoiceHdrService.getAssignEmployee();
trinvoiceform.setTrinvoiceList(transferinvoice);
log.info("++++"+trinvoiceform.getTrinvoiceList());
model.addAttribute("employees", employees.get(0).getFullname());
// model.addAttribute("transferinvoice", transferinvoice);
model.addAttribute("transferInvoiceHdr", transferInvoiceHdr);
//model.addAttribute("transferInvoice", transferinvoice);

return new ModelAndView("asset/transferInvoiceHdrForm", model.asMap());
}

我的 Pojo 与对象列表看起来像

public class TransferInvoiceForm {
private List<TransferInvoice> TrinvoiceList;
//getters and setters

在我的 JSP 中,我使用路径变量如下

<form:form method="post" action="/asset/invoice/searchctr" modelAttribute="transferInvoice">
<fieldset>
<c:forEach var="transferinvoiceType" items="${transferInvoice.TrinvoiceList}" varStatus="status">
<form:select path="TrinvoiceList[${status.index}].assetName" class="col-xs-12 col-lg-5 form-group">
<form:option value="0" selected="true">All</form:option>
<form:options value="${transferinvoiceType.assetName}"></form:options>
</form:select>
</c:forEach>
<c:forEach var="transferinvoiceType" items="${transferInvoice.TrinvoiceList}" varStatus="status">
<form:select path="TrinvoiceList[${status.index}].assettoLocation" class="col-xs-12 col-lg-5 form-group">
<form:option value="0" selected="true">All</form:option>
<form:options value="${transferinvoiceType.assettoLocation}"></form:options>
</form:select>
</c:forEach>

<button class="btn btn-primary" type="submit" class="col-xs-12 col-lg-6 form-group">
<fmt:message key="button.search" />
</button>
</fieldset>
</form:form>

另一个有用的 java bean

 public class TransferInvoice {
private String assetName;
private String assettoLocation;
private String actualTransferDate;
private String scanserialCode;
private String modelNum;
private boolean check;
//getters and setters

任何帮助我得到 500 的原因。我彻底检查并确认我的 jsp 绑定(bind)中存在问题。任何帮助,将不胜感激。

谢谢

最佳答案

您可以使用以下过程从这种情况中恢复。每当您使用 JSTL 表单标记时,在您的 jsp 页面中您可以使用:

<form:form commandName="viewModel" method="POST">

在 Controller 部分,您可以直接使用 TransferInvoice 模型从 jsp 页面获取所有数据。如果需要将数据保留在 TransferInvoiceForm pojo 中,那么您可以在 Controller 下管理它。因此您可以按照以下代码操作:

@RequestMapping(value ="yourValue", method = RequestMethod.POST)
protected ModelAndView showForm(@ModelAttribute("viewModel") TransferInvoice transferInvoice, final HttpServletRequest request, final HttpServletResponse response, Model model)throws Exception {
//use every thing for transferInvoice
}

使用method = RequestMethod.POST

关于java - Spring绑定(bind)jsp问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29566298/

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