From f83ee1e9c2a2ee10605446ea08daf3c870567f13 Mon Sep 17 00:00:00 2001
From: "yangkai.shen" <237497819@qq.com>
Date: Mon, 27 Nov 2017 17:41:56 +0800
Subject: [PATCH] =?UTF-8?q?spring=20boot=20=E9=9B=86=E6=88=90=20thymeleaf?=
=?UTF-8?q?=20=E6=A8=A1=E6=9D=BF=E5=BC=95=E6=93=8E?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 4 +-
TODO.md | 4 +-
spring-boot-demo-parent/pom.xml | 1 +
spring-boot-demo-template-thymeleaf/README.md | 100 ++++++++++++++++++
spring-boot-demo-template-thymeleaf/pom.xml | 31 ++++++
...gBootDemoTemplateThymeleafApplication.java | 25 +++++
.../src/main/resources/application.yml | 9 ++
.../src/main/resources/templates/index.html | 10 ++
...DemoTemplateThymeleafApplicationTests.java | 16 +++
9 files changed, 197 insertions(+), 3 deletions(-)
create mode 100644 spring-boot-demo-template-thymeleaf/README.md
create mode 100644 spring-boot-demo-template-thymeleaf/pom.xml
create mode 100644 spring-boot-demo-template-thymeleaf/src/main/java/com/xkcoding/springbootdemotemplatethymeleaf/SpringBootDemoTemplateThymeleafApplication.java
create mode 100644 spring-boot-demo-template-thymeleaf/src/main/resources/application.yml
create mode 100644 spring-boot-demo-template-thymeleaf/src/main/resources/templates/index.html
create mode 100644 spring-boot-demo-template-thymeleaf/src/test/java/com/xkcoding/springbootdemotemplatethymeleaf/SpringBootDemoTemplateThymeleafApplicationTests.java
diff --git a/README.md b/README.md
index 18e918a..655a1c1 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# Spring Boot Demo
-spring boot demo 是一个用来学习 spring boot 的项目,已经集成 actuator(监控)、admin(可视化监控)、logback(日志)、aopLog(通过 AOP 记录 web 请求日志)、统一异常处理( json 级别和页面级别)、freemarker、JPA(ORM 框架)、mybatis(ORM 框架)、redis-cache(缓存)、swagger(API 接口管理测试)、ureport2(中国式报表)模块,后续会集成activemq,email,shiro,websocket,quartz,netty等模块。
+spring boot demo 是一个用来学习 spring boot 的项目,已经集成 actuator(监控)、admin(可视化监控)、logback(日志)、aopLog(通过 AOP 记录 web 请求日志)、统一异常处理( json 级别和页面级别)、freemarker(模板引擎)、thymeleaf(模板引擎)、JPA(ORM 框架)、mybatis(ORM 框架)、redis-cache(缓存)、swagger(API 接口管理测试)、ureport2(中国式报表)模块,后续会集成activemq,email,shiro,websocket,quartz,netty等模块。
依赖的 Spring Boot 版本:
@@ -53,6 +53,7 @@ spring boot demo 是一个用来学习 spring boot 的项目,已经集成 actu
../spring-boot-demo-aoplog
../spring-boot-demo-exceptionhandler
../spring-boot-demo-template-freemarker
+ ../spring-boot-demo-template-thymeleaf
../spring-boot-demo-orm-jpa
../spring-boot-demo-orm-mybatis
../spring-boot-demo-cache-redis
@@ -152,6 +153,7 @@ spring boot demo 是一个用来学习 spring boot 的项目,已经集成 actu
| [spring-boot-demo-aoplog](./spring-boot-demo-aoplog) | spring-boot 使用 AOP 切面的方式记录 web 请求日志 |
| [spring-boot-demo-exceptionhandler](./spring-boot-demo-exceptionhandler) | spring-boot 统一异常处理,包括2种,一种返回统一的 json 格式,第二种统一跳转到异常页面 |
| [spring-boot-demo-template-freemarker](./spring-boot-demo-template-freemarker) | spring-boot 集成 freemarker 模板引擎 |
+| [spring-boot-demo-template-thymeleaf](./spring-boot-demo-template-thymeleaf) | spring-boot 集成 thymeleaf 模板引擎 |
| [spring-boot-demo-orm-jpa](./spring-boot-demo-orm-jpa) | spring-boot 集成 spring-boot-starter-data-jpa 操作数据库 |
| [spring-boot-demo-orm-mybatis](./spring-boot-demo-orm-mybatis) | spring-boot 集成 [mybatis-spring-boot-starter](https://github.com/mybatis/spring-boot-starter)、[mybatis-spring-boot-starter](https://github.com/alibaba/druid/tree/master/druid-spring-boot-starter) |
| [spring-boot-demo-cache-redis](./spring-boot-demo-cache-redis) | spring-boot 使用 Redis 做缓存 |
diff --git a/TODO.md b/TODO.md
index c3a8933..4c830a5 100644
--- a/TODO.md
+++ b/TODO.md
@@ -1,6 +1,6 @@
# spring-boot-demo 项目
-## 模块计划(已完成:13 / 35)
+## 模块计划(已完成:14 / 35)
- [x] ~~spring-boot-demo-helloworld(Helloworld 示例)~~
- [x] ~~spring-boot-demo-properties(读取配置文件信息)~~
@@ -10,7 +10,7 @@
- [x] ~~spring-boot-demo-aoplog(使用 AOP 拦截请求日志信息)~~
- [x] ~~spring-boot-demo-exceptionhandler(统一异常处理)~~
- [x] ~~spring-boot-demo-template-freemarker(使用模板引擎 - Freemarker)~~
-- [ ] spring-boot-demo-template-thymeleaf(使用模板引擎 - thymeleaf)
+- [x] ~~spring-boot-demo-template-thymeleaf(使用模板引擎 - thymeleaf)~~
- [ ] spring-boot-demo-template-beetl(使用模板引擎 - beetl)
- [ ] spring-boot-demo-template-enjoy(使用模板引擎 - JFinal-Enjoy)
- [ ] spring-boot-demo-orm-jdbctemplate(操作 SQL 关系型数据库 - JdbcTemplate)
diff --git a/spring-boot-demo-parent/pom.xml b/spring-boot-demo-parent/pom.xml
index 71becd1..807aae0 100644
--- a/spring-boot-demo-parent/pom.xml
+++ b/spring-boot-demo-parent/pom.xml
@@ -20,6 +20,7 @@
../spring-boot-demo-aoplog
../spring-boot-demo-exceptionhandler
../spring-boot-demo-template-freemarker
+ ../spring-boot-demo-template-thymeleaf
../spring-boot-demo-orm-jpa
../spring-boot-demo-orm-mybatis
../spring-boot-demo-cache-redis
diff --git a/spring-boot-demo-template-thymeleaf/README.md b/spring-boot-demo-template-thymeleaf/README.md
new file mode 100644
index 0000000..36ae7a7
--- /dev/null
+++ b/spring-boot-demo-template-thymeleaf/README.md
@@ -0,0 +1,100 @@
+# spring-boot-demo-template-thymeleaf
+依赖 [spring-boot-demo-parent](../spring-boot-demo-parent)、`spring-boot-starter-thymeleaf`
+
+### pom.xml
+
+```xml
+
+
+ 4.0.0
+
+ spring-boot-demo-template-thymeleaf
+ 0.0.1-SNAPSHOT
+ jar
+
+ spring-boot-demo-template-thymeleaf
+ Demo project for Spring Boot
+
+
+ com.xkcoding
+ spring-boot-demo-parent
+ 0.0.1-SNAPSHOT
+ ../spring-boot-demo-parent/pom.xml
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-thymeleaf
+
+
+
+
+ spring-boot-demo-template-thymeleaf
+
+
+
+```
+
+### application.yml
+
+```yaml
+server:
+ port: 8080
+ context-path: /demo
+spring:
+ thymeleaf:
+ mode: HTML5
+ encoding: UTF-8
+ content-type: text/html
+ cache: false
+```
+
+### SpringBootDemoTemplateThymeleafApplication.java
+
+```java
+@SpringBootApplication
+@Controller
+public class SpringBootDemoTemplateThymeleafApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SpringBootDemoTemplateThymeleafApplication.class, args);
+ }
+
+ @GetMapping({"", "/"})
+ public ModelAndView index(@RequestParam(defaultValue = "thymeleaf") String name) {
+ ModelAndView mv = new ModelAndView();
+ mv.addObject("name", name);
+ mv.setViewName("index");
+ return mv;
+ }
+}
+```
+
+### index.html
+
+```html
+
+
+
+
+ spring-boot-demo-template-thymeleaf
+
+
+
+
+
+```
+
+### 测试
+
+浏览器分别输入:
+
+http://localhost:8080/demo → Hello,thymeleaf!
+
+http://localhost:8080/demo?name=xkcoding → Hello,xkcoding!
+
+### Thymeleaf 语法
+
+待补充。。。
\ No newline at end of file
diff --git a/spring-boot-demo-template-thymeleaf/pom.xml b/spring-boot-demo-template-thymeleaf/pom.xml
new file mode 100644
index 0000000..d8f565f
--- /dev/null
+++ b/spring-boot-demo-template-thymeleaf/pom.xml
@@ -0,0 +1,31 @@
+
+
+ 4.0.0
+
+ spring-boot-demo-template-thymeleaf
+ 0.0.1-SNAPSHOT
+ jar
+
+ spring-boot-demo-template-thymeleaf
+ Demo project for Spring Boot
+
+
+ com.xkcoding
+ spring-boot-demo-parent
+ 0.0.1-SNAPSHOT
+ ../spring-boot-demo-parent/pom.xml
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-thymeleaf
+
+
+
+
+ spring-boot-demo-template-thymeleaf
+
+
+
\ No newline at end of file
diff --git a/spring-boot-demo-template-thymeleaf/src/main/java/com/xkcoding/springbootdemotemplatethymeleaf/SpringBootDemoTemplateThymeleafApplication.java b/spring-boot-demo-template-thymeleaf/src/main/java/com/xkcoding/springbootdemotemplatethymeleaf/SpringBootDemoTemplateThymeleafApplication.java
new file mode 100644
index 0000000..465f589
--- /dev/null
+++ b/spring-boot-demo-template-thymeleaf/src/main/java/com/xkcoding/springbootdemotemplatethymeleaf/SpringBootDemoTemplateThymeleafApplication.java
@@ -0,0 +1,25 @@
+package com.xkcoding.springbootdemotemplatethymeleaf;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.servlet.ModelAndView;
+
+@SpringBootApplication
+@Controller
+public class SpringBootDemoTemplateThymeleafApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SpringBootDemoTemplateThymeleafApplication.class, args);
+ }
+
+ @GetMapping({"", "/"})
+ public ModelAndView index(@RequestParam(defaultValue = "thymeleaf") String name) {
+ ModelAndView mv = new ModelAndView();
+ mv.addObject("name", name);
+ mv.setViewName("index");
+ return mv;
+ }
+}
diff --git a/spring-boot-demo-template-thymeleaf/src/main/resources/application.yml b/spring-boot-demo-template-thymeleaf/src/main/resources/application.yml
new file mode 100644
index 0000000..9b72a64
--- /dev/null
+++ b/spring-boot-demo-template-thymeleaf/src/main/resources/application.yml
@@ -0,0 +1,9 @@
+server:
+ port: 8080
+ context-path: /demo
+spring:
+ thymeleaf:
+ mode: HTML5
+ encoding: UTF-8
+ content-type: text/html
+ cache: false
\ No newline at end of file
diff --git a/spring-boot-demo-template-thymeleaf/src/main/resources/templates/index.html b/spring-boot-demo-template-thymeleaf/src/main/resources/templates/index.html
new file mode 100644
index 0000000..34cee6c
--- /dev/null
+++ b/spring-boot-demo-template-thymeleaf/src/main/resources/templates/index.html
@@ -0,0 +1,10 @@
+
+
+
+
+ spring-boot-demo-template-thymeleaf
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-boot-demo-template-thymeleaf/src/test/java/com/xkcoding/springbootdemotemplatethymeleaf/SpringBootDemoTemplateThymeleafApplicationTests.java b/spring-boot-demo-template-thymeleaf/src/test/java/com/xkcoding/springbootdemotemplatethymeleaf/SpringBootDemoTemplateThymeleafApplicationTests.java
new file mode 100644
index 0000000..35a0125
--- /dev/null
+++ b/spring-boot-demo-template-thymeleaf/src/test/java/com/xkcoding/springbootdemotemplatethymeleaf/SpringBootDemoTemplateThymeleafApplicationTests.java
@@ -0,0 +1,16 @@
+package com.xkcoding.springbootdemotemplatethymeleaf;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class SpringBootDemoTemplateThymeleafApplicationTests {
+
+ @Test
+ public void contextLoads() {
+ }
+
+}