java - 将 Spring 模型列表显示为简单字段

标签 java forms spring jsp tags

可以绑定(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/

相关文章:

java - 由 : java. sql.SQLException 引起:用户 'root' @'localhost' 的访问被拒绝(使用密码:YES)

java - 拦截方法调用并添加/丰富参数

java - 卡夫卡流: Grouping by a key in Json log

Java TimeUnit.MILLISECONDS.toDays() 给出了错误的结果

java - 如何通过托管 bean 显示 MySQL 数据?

CSS 替换表单的表格布局

java - Play Framework 2.0 表单助手 : from checkbox to List<String>

html - 使用 CSS 定位 reCAPTCHA 小部件

java - Spring Data JPA findById() 方法返回 null 而不是 Empty Optional

java - 象夫 : Cannot convert into sequence file