我正在将一个对象从 View (jsp) 传递到 Controller 。 该对象实际上是 aa list ,但是当我在 Controller 中迭代它时,我在列表的第一个和最后一个元素前面和后面添加了一个方括号,知道可能是什么原因吗?
<input type="hidden" name="customObjectList" value="${vobject.getCustomObjectList}" />
当我在 Controller 中提取它时:
"@RequestParam(required = true, value = " customObjectList" ) List <CustomObject> objectList
当我迭代对象并打印字段时,我会在前面和后面添加一个方括号。
for(CustomObject object: objectList)
{
sout(object.getField());
}
输出
[值1 值2 值3]
知道如何避免这种情况吗?
最佳答案
<c:forEach var="customObject" items="${vobject.getCustomObjectList}">
<td>
<input type="hidden" name="customObjectList" value= <c:out value="${customObject.getField()}" /> />
</td>
</c:forEach>
尝试这样的事情。 Spring 会将输入名称 customObjectList 值很好地放入该数组中!
关于java - 当对象列表从 View (jsp)传递到 Controller 时附加方括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52698914/