Browse Source

add spring-boot-thymeleaf

纯洁的微笑 7 years ago
parent
commit
b254a27a7f

+ 1 - 0
README.md

@@ -21,6 +21,7 @@ Spring boot使用的各种示例,以最简单、最实用为标准
 - [spring-boot-multi-mongodb](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-multi-mongodb):spring boot和mongodb多数据源的使用
 - [spring-boot-package-war](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-package-war):spring-boot打包成war包示例
 - [spring-boot-shiro](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-shiro):springboot 整合shiro rbac示例
+- [spring-boot-thymeleaf](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-thymeleaf):简单 spring boot thymeleaf 脚手架
 - [Favorites-web](https://github.com/cloudfavorites/favorites-web):云收藏(springboot实战开源软件)
 
 

+ 1 - 0
README_EN.md

@@ -22,4 +22,5 @@ Spring Boot Examples, Use the simplest and most useful scene demo.
 - [spring-boot-multi-mongodb](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-multi-mongodb):Spring Boot + multiMongodb
 - [spring-boot-package-war](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-package-war):Spring Boot package war
 - [spring-boot-shiro](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-shiro):spring boot shiro rbac demo 
+- [spring-boot-thymeleaf](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-thymeleaf):simple spring boot thymeleaf demo
 - [Favorites-web](https://github.com/cloudfavorites/favorites-web):Open source projects developed using Spring Boot

+ 35 - 0
spring-boot-thymeleaf/pom.xml

@@ -0,0 +1,35 @@
+<?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-thymeleaf</artifactId>
+    <name>spring-boot-thymeleaf</name>
+    <description>spring-boot-thymeleaf</description>
+    <parent>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>1.5.6.RELEASE</version>
+    </parent>
+
+    <properties>
+        <java.version>1.7</java.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-thymeleaf</artifactId>
+        </dependency>
+    </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+</project>

+ 15 - 0
spring-boot-thymeleaf/src/main/java/com/neo/thymeleaf/HelloController.java

@@ -0,0 +1,15 @@
+package com.neo.thymeleaf;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+@Controller
+public class HelloController {
+    @RequestMapping("/hello")
+    public String hello(Model model, @RequestParam(value="name", required=false, defaultValue="World") String name) {
+        model.addAttribute("name", name);
+        return "hello";
+    }
+}

+ 20 - 0
spring-boot-thymeleaf/src/main/java/com/neo/thymeleaf/ThymeleafApplication.java

@@ -0,0 +1,20 @@
+package com.neo.thymeleaf;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.boot.web.support.SpringBootServletInitializer;
+
+
+@SpringBootApplication
+public class ThymeleafApplication extends SpringBootServletInitializer {
+    @Override
+    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
+        return application.sources(ThymeleafApplication.class);
+    }
+
+    public static void main(String[] args) throws Exception {
+        SpringApplication.run(ThymeleafApplication.class, args);
+    }
+}
+

+ 1 - 0
spring-boot-thymeleaf/src/main/resources/application.properties

@@ -0,0 +1 @@
+spring.thymeleaf.cache: false

+ 10 - 0
spring-boot-thymeleaf/src/main/resources/templates/hello.html

@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html lang="en" xmlns:th="http://www.thymeleaf.org">
+<head>
+    <meta charset="UTF-8"/>
+    <title>Hello Thymeleaf!</title>
+</head>
+<body>
+    <p th:text="'Hello, ' + ${name} + '!'" />
+</body>
+</html>