10.2.1。環境構築へ
10.2.1.1.pomファイル
<?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コード
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ます。
<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。ラベル
•目:アクションは、バックエンド・コントローラーのパスを定義します。
•目:各1、シールドリング言語-文。
•目:フィールドのフォームフィールドを結合します。
•目:hrefがハイパーリンクを定義しました。
•目:HTMLタグの所有権に似たIDの文のIDのdivタグ、。
•目:条件文の場合。
•目:ファイルの内容を置き換えるために導入され、[レイアウト]タブが含まれます。
•目:エンタープライズagmentレイアウト]タブ、他の場所で、便利な参照コードスニペットを定義します。
•目:オブジェクトの置換オブジェクト。
•目:SRC画像カテゴリアドレスを導入しました。
•目:テキスト表示テキスト。
•目:valueプロパティの割り当て。
10.2.2.1.th:eachサイクル
<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。@ラベル
<a th:href="@{/product/comments(prodId=${prod.id},prodId2=${prod.id})}" >删除</a>
相当于
<a href="/sbe/product/comments?prodId=2&prodId2=2">查看</a>