可以绑定(bind)一个字符串列表(List)并将它们显示在 jsp 中的组合框中,如下所示:
<form:select path="countryId">
<form:option value="" label="Please Select"></form:option>
<form:options items="${countryList}" itemValue="countryId" itemLabel="countryName"/>
</form:select>
我希望此列表显示在<td>
中或<form:input>
就像字段一样,而不是在组合框中。
我将模型中的字符串列表绑定(bind)为
Map referenceData = new HashMap();
referenceData.put("OutputsList", Outputs);
在JSP中我使用
<c:forEach var="OutputsList" items="${Outputs}">
${OutputsList}
</c:forEach>
但列表未打印。可能是什么原因?
最佳答案
就这样做。
<c:forEach var="country" items="${countryList}">
<tr>
<td>${country.countryId}</td>
<td>${country.countryName}</td>
</tr>
</c:forEach>
并在服务器端使用 ModelAndView 对象
List<Country> countryList;
ModelAndView mv = new ModelAndView("index");
mv.addObject("country",countryList);
关于java - 将 Spring 模型列表显示为简单字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6813107/