简体   繁体   English

在 spring 引导中将文本值传递给 thymeleaf 视图

[英]Passing text value to thymeleaf view in spring boot

@RequestMapping(value = "alphabet")
public String index(Model model) {
    model.addAttribute("title", "Alphabet");
    return "categories/index";

We are at the ${title} page我们在 ${title} 页面

I'm trying to get title to display within html tags.我正在尝试在 html 标签中显示标题。 Is there a way to do this in spring boot?有没有办法在 spring 引导中做到这一点?

Yeah so this is absolutely possible in Thymeleaf.是的,所以这在 Thymeleaf 中是绝对可能的。 What you can do is change the title using the title tag and text parameter.您可以做的是使用标题标签和文本参数更改标题。 It is important to note that th will stand for the thymeleaf xml namespace.需要注意的是, th代表 thymeleaf xml 命名空间。 It it also important to note that this can be done with fragments .同样重要的是要注意,这可以通过片段来完成。

<title th:text="${title}></title>

Just use the th:text attribute as th:text="${title}只需将 th:text 属性用作th:text="${title}

DOCS: https://www.thymeleaf.org/doc/articles/standarddialect5minutes.html 文档:https://www.thymeleaf.org/doc/articles/standarddialect5minutes.html

Use th:text parameter for thymeleaf对 thymeleaf 使用th:text参数

<p align="center">We are at the <title th:text="${title}></title> page</p>

Find more details indocdoc中查找更多详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM