博客目标
快捷传送门
模板
thymeleaf模板
学习模板不废话直接上面导入pom依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
这里讲解的时候的时候是关闭缓存的(不关闭缓存有可能存在代码没有显示效果的问题)
将配置文件的后缀名改成.yml文件
spring.thymeleaf.cache=false
使用thymeleaf完成跳转页面
UserCpmtroller
package com.onlyk.springboot01.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
/**
* @author only老K
* @create 2019-12-28 6:08
*
* 介绍thymeleaf模板引擎的应用
*/
@Controller
@RequestMapping("/thymeleaf")
public class UserController {
@RequestMapping("/list")
public ModelAndView list(){
ModelAndView mv=new ModelAndView();
mv.setViewName("list");
return mv;
}
}
list.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>介绍thymeleaf模板引擎的应用</title>
</head>
<body>
介绍thymeleaf模板引擎的应用
</body>
</html>
thymeleaf模板语法讲解:
效果图:
相关代码:
list.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>介绍thymeleaf模板引擎的应用</title>
</head>
<body>
介绍thymeleaf模板引擎的应用,这里不能使用el表达式,因为el表达式是jsp特有的
<br>
${title}
<br>
直接使用el表达式:${title},这里如果是支持的时候是会显示出人员表这几个字
<br>
使用thymeleaf模板语法做获取Controller传递过来的title
<h3 th:text="${title}"></h3>
使用thymeleaf模板语法做获取Controller传递过来的User,这里需要做成表格的形式
<br>
<table border="1" cellpadding="0" cellspacing="0" width="600px">
<caption th:tex