Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring MVC+;FreeMarker:如何呈现选项标记?_Java_Spring Mvc_Freemarker - Fatal编程技术网

Java Spring MVC+;FreeMarker:如何呈现选项标记?

Java Spring MVC+;FreeMarker:如何呈现选项标记?,java,spring-mvc,freemarker,Java,Spring Mvc,Freemarker,Spring 3 MVC文档声明,选项标记可以如下呈现: <tr> <td>Country:</td> <td> <form:select path="country"> <form:options items="${countryList}" itemValue="code" itemLabel="name"/> </form

Spring 3 MVC文档声明,选项标记可以如下呈现:

<tr>
      <td>Country:</td>
      <td>
          <form:select path="country">
              <form:options items="${countryList}" itemValue="code" itemLabel="name"/>
          </form:select>
      </td>
</tr>
我应该用什么来代替FreeMarker模板中的${places},这样上面的工作就可以了


谢谢。

您可以尝试以下方法(不需要亲自测试)



希望这有帮助

您可以尝试以下方法(不需要亲自测试)



希望这有帮助

我在寻找完全相同的东西。我不知道为什么Spring的Freemarker宏库中没有包含这一功能,但幸运的是,它很容易实现:最佳做法是启动自己的宏库(比如说
mylib.ftl
),然后将宏放在那里:

<#macro selectOptions path options key value>
  <@spring.bind path/>
  <select id="${spring.status.expression}" name="${spring.status.expression}">
    <#list options as option>
      <option value="${option[key]?html}"<@spring.checkSelected option[key]/>>${option[value]?html}</option>
    </#list>
  </select>
</#macro>

${option[value]?html}
然后,您可以在Freemarker模板中使用新宏,如下所示:

<#import "/mylib.ftl" as mylib />
...
<@mylib.selectOptions "country" countryList "code" "name" />

...

HTH

我在寻找完全相同的东西。我不知道为什么Spring的Freemarker宏库中没有包含这一功能,但幸运的是,它很容易实现:最佳做法是启动自己的宏库(比如说
mylib.ftl
),然后将宏放在那里:

<#macro selectOptions path options key value>
  <@spring.bind path/>
  <select id="${spring.status.expression}" name="${spring.status.expression}">
    <#list options as option>
      <option value="${option[key]?html}"<@spring.checkSelected option[key]/>>${option[value]?html}</option>
    </#list>
  </select>
</#macro>

${option[value]?html}
然后,您可以在Freemarker模板中使用新宏,如下所示:

<#import "/mylib.ftl" as mylib />
...
<@mylib.selectOptions "country" countryList "code" "name" />

...

有点奇怪,但它能工作

  • 删除${“places”}并将其用作位置
  • 删除itemid并让spring为您处理它
所以你会有

<@form.select path="place">
   <@form.options items=places itemLabel="name"/>

</@form.select>

有点奇怪,但它可以工作

  • 删除${“places”}并将其用作位置
  • 删除itemid并让spring为您处理它
所以你会有

<@form.select path="place">
   <@form.options items=places itemLabel="name"/>

</@form.select>