【问题标题】:Passing text value to thymeleaf view in spring boot在 Spring Boot 中将文本值传递给 thymeleaf 视图
【发布时间】:2020-07-30 03:01:57
【问题描述】:
@RequestMapping(value = "alphabet")
public String index(Model model) {
    model.addAttribute("title", "Alphabet");
    return "categories/index";

我们在 ${title} 页面

我正在尝试让标题显示在 html 标记中。有没有办法在 Spring Boot 中做到这一点?

【问题讨论】:

标签: java spring-boot controller thymeleaf


【解决方案1】:

是的,所以这在 Thymeleaf 中是绝对可能的。您可以做的是使用标题标签和文本参数更改标题。需要注意的是,th 将代表 thymeleaf xml 命名空间。还需要注意的是,这可以通过fragments 完成。

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

【讨论】:

    【解决方案2】:

    只需将 th:text 属性用作th:text="${title}

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

    【讨论】:

      【解决方案3】:

      百里香叶使用th:text参数

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

      doc了解更多详情

      【讨论】:

      • @AxelKong 你试过这个解决方案了吗?
      猜你喜欢
      • 2018-11-02
      • 2017-10-28
      • 1970-01-01
      • 1970-01-01
      • 2018-05-07
      • 1970-01-01
      • 1970-01-01
      • 2018-05-24
      • 2021-07-06
      相关资源
      最近更新 更多