10.2.1. Environment to build
10.2.1.1.pom file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.wthink</groupId>
<artifactId>day706</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>day706</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.2.4.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
10.2.1.2.Application.properties
# thymeleaf
#开发配置为false,避免修改模板还要重启服务器
spring.thymeleaf.cache=false
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=utf-8
spring.thymeleaf.content-type=text/html
#前缀
spring.thymeleaf.prefix=classpath:/templates/
#后缀
spring.thymeleaf.suffix=.html
10.2.1.3.Controller Code
package com.bwie.springbootdemo12.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @描述:
* @作者:zhangyuyang
* @日期:2020/3/24 15:43
*/
@Controller
public class UserController {
@RequestMapping("/toIndex")
public String toIndex(Model model){
model.addAttribute("name","1712ab");
return "show";
}
}
10.2.1.4. Page
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Show User</title>
</head>
<body>
<table>
姓名: <p th:text="${name}"> 姓名</p>
</table>
</body>
</html>
10.2.2. Label
• th: action define the backend controller path.
• th: each 1, shield ring language - sentence.
• th: field form fields binding.
• th: href defined hyperlinks.
• th: ID statement id div tag, similar to the ownership of HTML tags.
• th: if conditional statement.
• th: include Layout tab, introduced to replace the contents of the file.
• th: Enterprise agment Layout tab, define a code snippet, convenient reference elsewhere.
• th: object replacement object.
• th: src picture category addresses introduced.
• th: text display text.
• th: value property assignment.
10.2.2.1.th:each cycle
<table>
<thead>
<tr>
<th>序号</th>
<th>用户名</th>
<th>密码</th>
<th>用户昵称</th>
</tr>
<tr th:each="user:${userlist}">
<td th:text="${user.id}"></td>
<td th:text="${user.username}"></td>
<td th:text="${user.password}"></td>
<td th:text="${user.petname}"></td>
</tr>
</thead>
</table>
10.2.2.2. @ Label
<a th:href="@{/product/comments(prodId=${prod.id},prodId2=${prod.id})}" >删除</a>
相当于
<a href="/sbe/product/comments?prodId=2&prodId2=2">查看</a>