其他分享
首页 > 其他分享> > thymeleaf

thymeleaf

作者:互联网





表达式


引入Thymeleaf的starter

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

在html文件中引入命名空间

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


例子

success.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1 th:text="${msg}">啊哈哈</h1>
<h2><a href="www.baidu.com" th:href="${link}">去百度</a></h2>
</body>
</html>

ViewController:

@Controller
public class ViewController {

    @RequestMapping("/haha")
    public String haha(Model model){

        //model中的数据会被自动放到请求域中,相当于request.setAttribute("a",aa)
        model.addAttribute("msg","你好");
        model.addAttribute("link","https://www.bilibili.com");
        return "success";
    }
}




标签:springboot,jar,boot,Thymeleaf,addAttribute,thymeleaf,model
来源: https://www.cnblogs.com/kakafa/p/15959149.html