SpringBoot: 9.整合thymeleaf(转)
1、创建maven项目,添加项目所需依赖

<!--springboot项目依赖的父项目-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent> <dependencies>
<!--注入springboot启动器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <!--注入springboot对thymeleaf视图技术的支持-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>

2、创建controller

package com.bjsxt.controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; /**
* Created by Administrator on 2019/2/8.
*/
@Controller
public class IndexController { @RequestMapping("/toIndex")
public String toIndex(Model model){
model.addAttribute("msg","index页面");
return "index";
}
}

3、创建thymeleaf模版文件index.html
目录位置:src/main/resources/templates
templates:该目录是安全的。意味着该目录下的内容是不允许外界直接访问的。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>thymeleaf</title>
</head>
<body>
<span th:text="${msg}"></span>
<hr>
<span th:text="hello"></span>
</body>
</html>

4、创建启动器,启动在浏览器中访问

package com.bjsxt; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; /**
* Created by Administrator on 2019/2/8.
*/
@SpringBootApplication
public class App { public static void main(String[] args){
SpringApplication.run(App.class,args);
}
}

目录结构
SpringBoot: 9.整合thymeleaf(转)的更多相关文章
- SpringBoot 同时整合thymeleaf html、vue html和jsp
问题描述 SpringBoot如何同时访问html和jsp SpringBoot访问html页面可以,访问jsp页面报错 SpringBoot如何同时整合thymeleaf html.vue html ...
- thymeleaf第二篇:理解原理并为后面springboot进行整合进行铺垫
官方入门之从虚拟商店理解thymeleaf 参考文档: 简单使用Thymeleaf API渲染模板生成静态页面 邮件通知改造之Thymeleaf渲染模板生成静态页面--看懂会帮助理解springboo ...
- 【Springboot】Springboot整合Thymeleaf模板引擎
Thymeleaf Thymeleaf是跟Velocity.FreeMarker类似的模板引擎,它可以完全替代JSP,相较与其他的模板引擎,它主要有以下几个特点: 1. Thymeleaf在有网络和无 ...
- Springboot整合thymeleaf模板
Thymeleaf是个XML/XHTML/HTML5模板引擎,可以用于Web与非Web应用. Thymeleaf的主要目标在于提供一种可被浏览器正确显示的.格式良好的模板创建方式,因此也可以用作静态建 ...
- SpringBoot:2.SpringBoot整合Thymeleaf模板引擎渲染web视图
在Web开发过程中,Spring Boot可以通过@RestController来返回json数据,那如何渲染Web页面?Spring Boot提供了多种默认渲染html的模板引擎,主要有以下几种: ...
- 三、SpringBoot整合Thymeleaf视图
目录 3.1 Thymeleaf视图介绍 3.2 创建SpringBoot项目 3.2 配置Thymeleaf 3.3 编写Demo 3.4 小结 3.1 Thymeleaf视图介绍 先看下官网的介绍 ...
- 【SpringBoot】SpringBoot/MyBatis/MySql/thymeleaf/Log4j整合工程
工程下载地址:https://files.cnblogs.com/files/xiandedanteng/MMSpringWeb20191027-1.rar 工程目录结构如图: 1.创建工程 有些网文 ...
- SpringBoot 整合 Thymeleaf & 如何使用后台模板快速搭建项目
如果你和我一样,是一名 Java 道路上的编程男孩,其实我不太建议你花时间学 Thymeleaf,当然他的思想还是值得借鉴的.但是他的本质在我看来就是 Jsp 技术的翻版(Jsp 现在用的真的很少很少 ...
- SpringBoot 整合thymeleaf
1.Thymeleaf介绍(官网推荐:https://www.thymeleaf.org/doc/articles/thymeleaf3migration.html) Thymeleaf是跟Veloc ...
- SpringBoot整合Thymeleaf
一个整合Thymeleaf与Mybatis的CRUD例子 整合Mybatis例子 一.添加maven依赖 <dependency> <groupId>org.springfra ...
随机推荐
- Access viewchild from another component
https://stackoverflow.com/questions/50935728/access-viewchild-from-another-component =============== ...
- 【WEB】jQuery 判断复选框是否选中
1.背景 在 jQuery 1.6 版本之前,判断方式 <input type='checkbox' id='test'/> <script> var isChecked = ...
- 创建yum本地仓库,将阿里仓库同步到本地,并定时更新
很多时候为了加速自己内部的rpm包安装速度,都会搭建自己的yum源仓库,而使用系统光盘自带的源,由于软件版本比较落后,所以不太适用,而大家都在用的阿里仓库比较好用,所以就想到了把阿里仓库的rpm全部拉 ...
- ActiveMQ部署和代码尝试(二)
部署和代码尝试 1. 部署在linux 上的acvtiveMQ 要可以通过前台windows 的页面访问,必须把linux 的IP和 windows的 IP 地址配置到同一个网关下 .这种情况一般都是 ...
- Mapreduce案例之Pi值估算
题目: 这个程序的原理是这样的.假如有一个边长为1的正方形.以正方形的一个端点为圆心,以1为半径,画一个圆弧,于是在正方形内就有了一个直角扇形.在正方形里随机生成若干的点,则有些点是在扇形内,有些点是 ...
- 12 canvas 画布 - 基础
二.线条的绘制和填充 在canvas中,各个图像绘制代码可以通过beginPath()和closePath()这两个函数进行包裹,主要用于分割各个画图,表示开始和结束.线条的绘制主要调用方法是move ...
- 牛客练习赛3 F - 监视任务——贪心&&树状数组
题目 链接 $Reki$ 在课余会接受一些民间的鹰眼类委托,即远距离的狙击监视防卫..$Reki$ 一共接收到$m$份委托,这些委托与 $n$ 个直线排布的监视点相关.第 $i$ 份委托的内容为:对于 ...
- [Cypress] Find Unstubbed Cypress Requests with Force 404
Requests that aren't stubbed will hit our real backend. To ensure we've stubbed all our routes, we c ...
- [Spring Boot] Set Context path for application in application.properties
If you were using Microservice with Spring Boot to build different REST API endpoints, context path ...
- java8 time计算时间差
最近使用Java8编写代码时,需要计算时间差,现整理如下 前言 本次使用了Java8提供的ChronoUnit工具类,它主要提供以下几种时间维度 枚举 枚举 说明 NANOS 毫微秒(毫秒的10000 ...