forked from xkcoding/spring-boot-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
197 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# spring-boot-demo-template-thymeleaf | ||
依赖 [spring-boot-demo-parent](../spring-boot-demo-parent)、`spring-boot-starter-thymeleaf` | ||
|
||
### pom.xml | ||
|
||
```xml | ||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>spring-boot-demo-template-thymeleaf</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>spring-boot-demo-template-thymeleaf</name> | ||
<description>Demo project for Spring Boot</description> | ||
|
||
<parent> | ||
<groupId>com.xkcoding</groupId> | ||
<artifactId>spring-boot-demo-parent</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<relativePath>../spring-boot-demo-parent/pom.xml</relativePath> | ||
</parent> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-thymeleaf</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>spring-boot-demo-template-thymeleaf</finalName> | ||
</build> | ||
|
||
</project> | ||
``` | ||
|
||
### 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 | ||
<!DOCTYPE html> | ||
<html lang="en" xmlns:th="http://www.thymeleaf.org"> | ||
<head> | ||
<meta charset="UTF-8"/> | ||
<title>spring-boot-demo-template-thymeleaf</title> | ||
</head> | ||
<body> | ||
<span th:text="'Hello,'+${name}+'!'"></span> | ||
</body> | ||
</html> | ||
``` | ||
|
||
### 测试 | ||
|
||
浏览器分别输入: | ||
|
||
http://localhost:8080/demo → Hello,thymeleaf! | ||
|
||
http://localhost:8080/demo?name=xkcoding → Hello,xkcoding! | ||
|
||
### Thymeleaf 语法 | ||
|
||
待补充。。。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>spring-boot-demo-template-thymeleaf</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>spring-boot-demo-template-thymeleaf</name> | ||
<description>Demo project for Spring Boot</description> | ||
|
||
<parent> | ||
<groupId>com.xkcoding</groupId> | ||
<artifactId>spring-boot-demo-parent</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<relativePath>../spring-boot-demo-parent/pom.xml</relativePath> | ||
</parent> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-thymeleaf</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>spring-boot-demo-template-thymeleaf</finalName> | ||
</build> | ||
|
||
</project> |
25 changes: 25 additions & 0 deletions
25
.../xkcoding/springbootdemotemplatethymeleaf/SpringBootDemoTemplateThymeleafApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
spring-boot-demo-template-thymeleaf/src/main/resources/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
server: | ||
port: 8080 | ||
context-path: /demo | ||
spring: | ||
thymeleaf: | ||
mode: HTML5 | ||
encoding: UTF-8 | ||
content-type: text/html | ||
cache: false |
10 changes: 10 additions & 0 deletions
10
spring-boot-demo-template-thymeleaf/src/main/resources/templates/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" xmlns:th="http://www.thymeleaf.org"> | ||
<head> | ||
<meta charset="UTF-8"/> | ||
<title>spring-boot-demo-template-thymeleaf</title> | ||
</head> | ||
<body> | ||
<span th:text="'Hello,'+${name}+'!'"></span> | ||
</body> | ||
</html> |
16 changes: 16 additions & 0 deletions
16
...ding/springbootdemotemplatethymeleaf/SpringBootDemoTemplateThymeleafApplicationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() { | ||
} | ||
|
||
} |