Thymleaf - 如何在html文档上调用模型属性

时间:2017-08-03 04:41:45

标签: spring spring-mvc spring-boot thymeleaf

我试图渲染一个webapge并使用thymleaf属性" url"添加了model.addAttribute,但未在html文档上显示属性 我的document.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>

2 个答案:

答案 0 :(得分:1)

请使用此表达式绑定对话框网址:@{${dialogurl}}

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

@前缀用于指定链接,$前缀用于绑定模型值。

答案 1 :(得分:0)

使用$绑定数据。

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