【问题标题】:Spring Boot with Freemarker - form tags带有 Freemarker 的 Spring Boot - 表单标签
【发布时间】:2015-05-04 12:39:23
【问题描述】:

我想将 Spring Boot MVC 与 Freemarker 一起使用,并以类似于使用 JSP 标签的方式显示表单。例如。这种形式:

<form:form method="post" action="save" modelAttribute="form" class="form-horizontal">
    <form:hidden path="id"/>
    <div class="form-group">
        <label for="name" class="col-sm-2 control-label">Name</label>
        <div class="col-sm-10">
            <form:input id="name" path="name" class="form-control" />
        </div>
    </div>
</form:form>

当然不支持form:form、form:input、form:hidden等标签。有没有办法将模型绑定到 Freemarker 中的视图?

【问题讨论】:

  • 你读过the reference guide吗?
  • 不欣赏居高临下的 cmets....thanx
  • 我参考的部分的参考指南中解释了如何做到这一点。在提问之前,您可能需要阅读官方文档。
  • 一个简单的答案:“你可以在....找到它”更容易阅读。自然,我已经阅读了文档但没有找到它。否则,我不会发布它。

标签: java spring spring-mvc spring-boot freemarker


【解决方案1】:

这里是:

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/view.html#view-simple-binding

<!-- freemarker macros have to be imported into a namespace. We strongly
recommend sticking to spring -->
<#import "/spring.ftl" as spring />
<html>
    ...
    <form action="" method="POST">
        Name:
        <@spring.bind "command.name" />
        <input type="text"
            name="${spring.status.expression}"
            value="${spring.status.value?default("")}" /><br>
        <#list spring.status.errorMessages as error> <b>${error}</b> <br> </#list>
        <br>
        ...
        <input type="submit" value="submit"/>
    </form>
    ...
</html>

【讨论】:

    猜你喜欢
    • 2019-10-19
    • 2015-09-24
    • 2018-02-05
    • 1970-01-01
    • 2016-02-18
    • 2019-01-10
    • 2014-09-27
    • 2018-02-08
    • 1970-01-01
    相关资源
    最近更新 更多