2015-05-04 93 views
0

我想使用Spring Boot MVC和Freemarker一起使用,并以类似的方式显示表单以及如何使用JSP标签完成。例如。这种形式:带Freemarker的Spring Boot - 表单标签

<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:input,form:hidden等不被支持。有没有办法将模型绑定到Freemarker中的视图?

+0

你读过[参考指南](http://docs.spring.io/spring/docs/current/spring-framework-reference/ HTML/view.html#视图-速度)? –

+0

不高兴的评论不赞赏.... thanx – checklist

+0

如何做到这一点已经在我参考的部分参考指南中解释。在提问之前,您可能需要阅读官方文档。 –

回答

4

这就是:

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>