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() { + } + +}