Spring Boot 2.0 整合Thymeleaf 模板引擎
本节将和大家一起实战Spring Boot 2.0 和thymeleaf 模板引擎
1. 创建项目

2. 使用Spring Initlizr 快速创建Spring Boot 应用程序

3. 填写项目配置信息

4. 添加Web 模块

5. 添加thymeleaf 模块

6. 项目保存路径

7. POM.xml 添加thymeleaf依赖
<?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> <groupId>com.xingyun</groupId>
<artifactId>srping-boot-with-thymeleaf-sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>srping-boot-with-thymeleaf-sample</name>
<description>Demo project for Spring Boot</description> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>
8. 配置application.properties
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html
# 关闭缓存,即时刷新,上线生产环境需改成true
spring.thymeleaf.cache=false
9. 创建模板文件

index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body> this is index.html
</body>
</html>
welcome.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
this is welcome.html
</body>
</html>
10.创建Controller
package com.xingyun.srpingbootwiththymeleafsample; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
public class HomeController { @GetMapping(value = "/")
public String index(){
return "/views/index";
} @GetMapping(value = "/welcome")
public String welcome(){
return "/views/welcome";
}
}
11. 访问 http://127.0.0.1:8080

12. 访问http://127.0.0.1:8080/welcome

Spring Boot 2.0 整合Thymeleaf 模板引擎的更多相关文章
- Spring Boot 2.0 整合 FreeMarker 模板引擎
		
本篇博文将和大家一起使用Spring Boot 2.0 和FreeMarker 模板引擎整合实战. 1. 创建新的项目 2. 填写项目配置信息 3. 勾选web 模块 4. 勾选freemarker模 ...
 - Spring Boot Web开发与thymeleaf模板引擎
		
简介: 使用Springboot应用,选中需要的模块, Spring已经默认将场景配置好了,只需在配置文件中少量配置就可以运行起来 自己编写业务代码 自动配置原理 这个场景Springboot帮我们配 ...
 - Spring Boot Web开发中Thymeleaf模板引擎的使用
		
这里使用的是idea 1.新建Spring Boot项目 File-->New-->Project...,然后选择左边的Spring Initializr-->Next,可根据自己的 ...
 - Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客
		
==他的博客应该不错,没有细看 Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客 http://blog.csdn.net/u012706811/article/det ...
 - spring boot 2.0 整合 elasticsearch6.5.3,spring boot 2.0 整合 elasticsearch NoNodeAvailableException
		
原文地址:spring boot 2.0 整合 elasticsearch NoNodeAvailableException 原文说的有点问题,下面贴出我的配置: 原码云项目地址:https://gi ...
 - Spring Boot 2.0 整合携程Apollo配置中心
		
原文:https://www.jianshu.com/p/23d695af7e80 Apollo(阿波罗)是携程框架部门研发的分布式配置中心,能够集中化管理应用不同环境.不同集群的配置,配置修改后能够 ...
 - SpringBoot:2.SpringBoot整合Thymeleaf模板引擎渲染web视图
		
在Web开发过程中,Spring Boot可以通过@RestController来返回json数据,那如何渲染Web页面?Spring Boot提供了多种默认渲染html的模板引擎,主要有以下几种: ...
 - Spring Boot WebFlux-04——WebFlux 整合 Thymeleaf
		
第04课:WebFlux 整合 Thymeleaf 上一篇介绍的是用 MongoDB 来实现 WebFlux 对数据源的操作,那么有了数据需要渲染到前台给用户展示,这就是本文关心的 View 层,Vi ...
 - 【Springboot】Springboot整合Thymeleaf模板引擎
		
Thymeleaf Thymeleaf是跟Velocity.FreeMarker类似的模板引擎,它可以完全替代JSP,相较与其他的模板引擎,它主要有以下几个特点: 1. Thymeleaf在有网络和无 ...
 
随机推荐
- jquery数组(sort() 排序)
			
HTML: <h3>字符串数组排序前</h3> <div id="show5"></div> <h3>排序后</h ...
 - 6-3 矩阵链成  uva 442
			
较为简单的栈题 思路比较好 一次ac 1.char word :word=A:直接 a[word]=xxxx,不用 a[‘word’]=xxxx #include<bits/stdc++.h& ...
 - 第六章|网络编程-socket开发
			
1.计算机基础 作为应用开发程序员,我们开发的软件都是应用软件,而应用软件必须运行于操作系统之上,操作系统则运行于硬件之上,应用软件是无法直接操作硬件的,应用软件对硬件的操作必须调用操作系统的接口,由 ...
 - maven加载第三方jar不能加载
			
这个问题处于项目组,总算是解决了.下面是一些自己的做法. 1.说明介绍 公司现在用的是spring+maven,使用的公共maven库没有问题,但是想要把一些老的项目改造这种框架会出现一些问题. 因为 ...
 - 各种浏览器下的页面元素xpath获取方法
			
参考链接: http://blog.sina.com.cn/s/blog_654c6ec70100v1i2.html
 - C语言中的地址传递(传指针,传递给形参的指针仍然是实参指针的一份拷贝)
			
先看一个例子:这个程序为什么会崩溃? #include <stdio.h> #include <stdlib.h> int f(int *q) { ; q = (int*)ma ...
 - linux下php命令无法使用如何解决
			
本文主要和大家分享linux下php命令无法使用如何解决,测试是否添加php环境变量方法: 如下:输入php -v 显示 php 命令没有找到 [root@iz8vbhc4d7zoazstpw7gw8 ...
 - mac下配置Apache虚拟域名方案,以及遇到的坑(转)
			
1. 配置Apache虚拟域名 1.执行 sudo vi /etc/apache2/httpd.conf 开始配置httpd.conf 的文件; //配置listen 80端口(默认配置), ...
 - jupyter notebook connecting to kernel problem
			
前几天帮同学配置 python 和 anaconda 环境,在装 jupyter notebook 时,出了点问题,搞了一天半终于搞好了,也是在 github 里找到了这个问题的解答. 当时显示的是无 ...
 - BZOJ.4589.Hard Nim(FWT)
			
题目链接 FWT 题意即,从所有小于\(m\)的质数中,选出\(n\)个数,使它们异或和为\(0\)的方案数. 令\(G(x)=[x是质数]\),其实就是对\(G(x)\)做\(n\)次异或卷积后得到 ...