thymeleaf
作者:互联网
-
springboot默认打包为jar包,jar包是一个压缩包,但是jsp不支持在压缩包内编译,因此springboot默认不支持jsp
-
Spring官方支持的服务的渲染模板有Thymeleaf和Freemarker等,Thymeleaf是用来开发Web和独立环境项目的服务器端的Java模版引擎
-
缺点: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