数据传递,网页模板thymeleaf

springboot

网页模板thymeleaf

POM配置:

<dependency>
    <groupId>org.thymeleaf</groupId>
    <artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
    <groupId>org.thymeleaf.extras</groupId>
    <artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>

模板页配置:

<html lang="en" xmlns:th="http://www.thymeleaf.org">

 

转意用utext(不是文本)

 后台:

    public String test(Model model) {
        model.addAttribute("msg", "<h1>html.chen</h1>");
        return "/test";
    }

 

<div th:text="${msg}"></div>
<div th:utext="${msg}"></div>

获取数组:

<h3 th:each="user:${users}" th:text="${user}"></h3>
model.addAttribute("users", Arrays.asList("chen","li"));

 在标签内插入数据

<h3 th:each="user:${users}">[[${user}]]</h3>   
原文地址:https://www.cnblogs.com/bingxing/p/13652102.html