2015-05-04 95 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>