Spring MVC:List< E>需要作为命令对象传递 [英] Spring MVC : List<E> need to pass as command object

查看:67
本文介绍了Spring MVC:List< E>需要作为命令对象传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将List作为commandObject传递.

I need to pass List as commandObject.

我的代码

public class Employee 
{       
List<Dept> dlist = new ArrayList<Dept>();    
public List<Dept> getDlist()
    {
return dlist;
}    
public void setDlist(List<Dept> dlList)
    {
this.dlist = dlist;
}       
}

我的jsp页面

<c:forEach var="d" items="${dlist}">
<spring:bind path="dlist[0].projectId">
<input type="text" name="projectId" value='<c:out value="${d.projectId}" />' />
</spring:bind>
</c:forEach>  

但是它没有过去,我犯了错误,可以提出任何建议.

But it not passing, where i making mistake, can any suggest.

推荐答案

您的forEach循环已损坏,您应该遍历命令对象列表中的元素.

Your forEach loop is broken you should iterate over the elements in your List of the command Object.

使用 form标签代替 spring:bind标签

尝试这样

<c:forEach var="d" items="${command.dlist}" varStatus="status">
  <form:input path="dlist[status.index].projectId" />
</c:forEach>

这篇关于Spring MVC:List&lt; E&gt;需要作为命令对象传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆