Browse Source

thymeleaf模板

YeLuo 5 years ago
parent
commit
b66e2a62f0

+ 9 - 0
pom.xml

@@ -96,6 +96,15 @@
96
 			<artifactId>druid-spring-boot-starter</artifactId>
96
 			<artifactId>druid-spring-boot-starter</artifactId>
97
 			<version>1.1.0</version>
97
 			<version>1.1.0</version>
98
 		</dependency>
98
 		</dependency>
99
+		<!-- thymeleaf -->
100
+		<dependency>
101
+			<groupId>org.springframework.boot</groupId>
102
+			<artifactId>spring-boot-starter-thymeleaf</artifactId>
103
+		</dependency>
104
+		<dependency>
105
+			<groupId>net.sourceforge.nekohtml</groupId>
106
+			<artifactId>nekohtml</artifactId>
107
+		</dependency>
99
 		<!-- commons -->
108
 		<!-- commons -->
100
 		<dependency>
109
 		<dependency>
101
 			<groupId>org.apache.commons</groupId>
110
 			<groupId>org.apache.commons</groupId>

+ 11 - 1
src/main/java/com/yingying/tourist/web/TestController.java

@@ -1,10 +1,14 @@
1
 package com.yingying.tourist.web;
1
 package com.yingying.tourist.web;
2
 
2
 
3
 import com.yingying.tourist.result.MessageResult;
3
 import com.yingying.tourist.result.MessageResult;
4
+import org.springframework.stereotype.Controller;
4
 import org.springframework.web.bind.annotation.GetMapping;
5
 import org.springframework.web.bind.annotation.GetMapping;
6
+import org.springframework.web.bind.annotation.RequestMapping;
5
 import org.springframework.web.bind.annotation.RestController;
7
 import org.springframework.web.bind.annotation.RestController;
6
 
8
 
7
-@RestController
9
+import java.util.Map;
10
+
11
+@Controller
8
 public class TestController {
12
 public class TestController {
9
 
13
 
10
     @GetMapping(value = {"/",""})
14
     @GetMapping(value = {"/",""})
@@ -16,4 +20,10 @@ public class TestController {
16
     public MessageResult<String> helloWorld(){
20
     public MessageResult<String> helloWorld(){
17
         return new MessageResult<String>().ok("hello,world");
21
         return new MessageResult<String>().ok("hello,world");
18
     }
22
     }
23
+
24
+    @RequestMapping("/index")
25
+    public String index(Map<String, Object> map){
26
+        map.put("user", "YeLuoFengXing");
27
+        return "index";
28
+    }
19
 }
29
 }

+ 0 - 0
src/main/resources/application.properties


+ 3 - 0
src/main/resources/env/dev/application.yml

@@ -60,6 +60,9 @@ spring:
60
       enabled: true
60
       enabled: true
61
       max-file-size: 50mb
61
       max-file-size: 50mb
62
       max-request-size: 200mb
62
       max-request-size: 200mb
63
+  thymeleaf:
64
+    cache: false
65
+    mode: LEGACYHTML5
63
 
66
 
64
 mybatis-plus:
67
 mybatis-plus:
65
   # 如果是放在src/main/java目录下 classpath:/com/yourpackage/*/mapper/*Mapper.xml
68
   # 如果是放在src/main/java目录下 classpath:/com/yourpackage/*/mapper/*Mapper.xml

+ 7 - 0
src/main/resources/templates/index.html

@@ -0,0 +1,7 @@
1
+<!DOCTYPE html>
2
+<html xmlns:th="http://www.thymeleaf.org">
3
+<head>
4
+    <meta charset="UTF-8"/>
5
+    <title>Insert title here</title></head>
6
+<body><p>Hello!<span th:text="${user}"></span>!<br/>welcom to Thymeleaf's world</p></body>
7
+</html>