我在下面显示的控制器方法时总是得到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与objets列表看起来像
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绑定中退出。任何帮助,将不胜感激。
由于
答案 0 :(得分:1)
您可以使用以下过程从此情况中恢复。 无论何时使用JSTL表单标记,都可以在jsp页面中使用:
<form:form commandName="viewModel" method="POST">
在控制器部分,您可以直接使用TransferInvoice模型从jsp页面获取所有数据。如果有必要将数据保存在TransferInvoiceForm pojo中,那么您可以在控制器下管理它。 所以你可以按照以下代码:
@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
答案 1 :(得分:0)
尝试用path="TrinvoiceList[
替换path="transferinvoiceType[
,我相信你应该做得很好。这里的问题是你可以使用c:foreach中var属性的值集来访问你正在迭代的arraylist元素,当你查看代码时,你会看到你试图直接访问对象的属性。