gpt4 book ai didi

java - 如何在 Spring 中从 UI 获取对象列表?

转载 作者:行者123 更新时间:2023-12-01 14:09:33 26 4
gpt4 key购买 nike

我已在 UI 上显示了数组列表值。 Arraylist 包含 pojo 类“Preference” Preference 类有 3 个 String 成员 PreferenceName、PreferenceType 和 PreferenceValue。
在 jsp 中,我迭代了 arraylist 并显示了 PreferenceName ,以及它的值(使用单选按钮显示),无论它是 true 还是 false。
现在当用户提交表单时。我想要包含值的数组列表。我正在使用 Spring。我正在获取其他值,但有什么方法可以获取数组列表值。那么我需要做什么..?

                        <c:forEach items="${preferences.preferenceList}" var="preference">
<tr height="35px" bgcolor="#fafafa" bordercolor="#FFF">
<td width="50%"><c:out value="${preference.preferenceName}"/></td>
<td width="20%">
<c:if test="${preference.preferenceType=='boolean'}">
<c:if test="${preference.preferenceValue=='true'}">
<input type="radio" name="${preference.preferenceName}" value="true" checked="true">Yes &nbsp;
<input type="radio" name="${preference.preferenceName}" value="false" >No &nbsp;
</c:if>
<c:if test="${preference.preferenceValue=='false'}">
<input type="radio" name="${preference.preferenceName}" value="true" > Yes &nbsp;
<input type="radio" name="${preference.preferenceName}" value="false" checked="true" >No
</c:if>
</c:if>
</td>
</tr>
</c:forEach>

最佳答案

试试这个:

<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<c:forEach items="${preferences.preferenceList}" var="preference" varStatus="itemRow">
<c:set var="varPath" value="preferenceList[${itemRow.index}]"/>
<tr height="35px" bgcolor="#fafafa" bordercolor="#FFF">
<td width="50%">
<form:label path="${varPath}.preferenceName">${preference.preferenceName}</form:label>
</td>
<td width="20%">
<c:if test="${preference.preferenceType=='boolean'}">
<form:radiobutton path="${varPath}.preferenceValue" value="true">Yes</form:radiobutton>
<form:radiobutton path="${varPath}.preferenceValue" value="false">No</form:radiobutton>
</c:if>
</td>
</tr>
</c:forEach>

关于java - 如何在 Spring 中从 UI 获取对象列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18631159/

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