2017-08-03 21 views
0

我試圖渲染一個webapge並使用與model.addAttribute一起添加的thymleaf屬性「url」,但該屬性不在beeing上顯示在html文檔中。
我document.html文件的路徑是在這裏:Thymleaf - 如何調用模型HTML文檔的屬性

/templates/webpage/document.html

@RequestMapping(value = "/webpage/document") 
    public String document(HttpServletRequest req, Model model) { 

     model.addAttribute("dialogurl", url); 
     return "/webpage/document"; 
    } 

下面是HTML文件

<!DOCTYPE html> 
<html xmlns:th="http://www.thymeleaf.org" th:include="wrapperdialog :: page"> 
<head> 
    <title></title> 
</head> 
<body> 
<div th:fragment="content"> 
    <div class="container dialogpage"> 
     <div class="row"> 
      <div class="col-md-12"> 
       <div id="typeform" th:attr="data-url=*{dialogurl}"> 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 

回答

1

請用這句話來綁定對話框網址:@{${dialogurl}}

<div id="typeform" th:attr="[email protected]{${dialogurl}}"> 

@前綴用於指定一個鏈接,$前綴用於模型值綁定。

0

使用$將數據綁定。

<div id="typeform" th:attr="data-url=${dialogurl}">