1、在application.properties配置文件中添加 thymeleaf 的配置信息

spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=root spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false

2、在pom.xml中引入thymeleaf 的jar包

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

3、创建PageController并添加index方法

package com.cppdy.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
public class PageController { @RequestMapping("index")
public String index(Model model) {
model.addAttribute("name","吹泡泡的魚");
return "index";
} }

4、在src/main/resources下创建templates(默认访问此文件下的html),并创建index.html

   在src/main/resources下创建static(默认访问此文件夹下的静态文件),在static文件夹创建images文件夹,并放入一张图片

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>SpringBoot</title>
</head>
<body>
Welcome to cppdy
<p th:text="${name}"></p>
<img alt="吹泡泡的魚" th:src="@{/images/logo.jpg}"/>
<br/>
<input th:value="${name}"/>
</body>
</html>

注:@表示当前项目路径,static文件夹是系统默认加载的静态文件路径

SpringBoot集成前端模版(thymeleaf)的更多相关文章

  1. Spring Boot—06集成前端模板thymeleaf

    Spring Boot建议使用这些模板引擎,避免使用JSP,若一定要使用JSP将无法实现Spring Boot的多种特性 pom.xml <dependency> <groupId& ...

  2. SpringBoot集成Freemarker与Thymeleaf

    一:概括 pom.xml添加依赖 配置application.yml HTML页面使用表达式 二:Freemarker模板引擎 1.添加依赖 <!-- ftl模板引擎 --> <de ...

  3. SpringBoot集成freemarker和thymeleaf模板

    1.在MAVEN工程POM.XML中引入依赖架包 <!-- 引入 freemarker 模板依赖 --> <dependency> <groupId>org.spr ...

  4. 九、SpringBoot集成Thymeleaf模板引擎

    Thymeleaf咋读!??? 呵呵,是不是一脸懵逼...哥用我的大学四级英文知识告诉你吧:[θaimlif]. 啥玩意?不会音标?...那你就这样叫它吧:“赛母李府”,大部分中国人是听不出破绽的.. ...

  5. Springboot 集成 Thymeleaf 及常见错误

    Thymeleaf模板引擎是springboot中默认配置,与freemarker相似,可以完全取代jsp,在springboot中,它的默认路径是src/main/resources/templat ...

  6. springboot集成websocket实现向前端浏览器发送一个对象,发送消息操作手动触发

    工作中有这样一个需示,我们把项目中用到代码缓存到前端浏览器IndexedDB里面,当系统管理员在后台对代码进行变动操作时我们要更新前端缓存中的代码怎么做开始用想用版本方式来处理,但这样的话每次使用代码 ...

  7. SpringBoot集成thymeleaf(自定义)模板中文乱码的解决办法

    楼主今天在学习SpringBoot集成thymelaf的时候报了中文乱码的错误,经过网上的搜索,现在得到解决的办法,分享给大家: package com.imooc.config; import or ...

  8. SpringBoot整合Jsp和Thymeleaf (附工程)

    前言 本篇文章主要讲述SpringBoot整合Jsp以及SpringBoot整合Thymeleaf,实现一个简单的用户增删改查示例工程.事先说明,有三个项目,两个是单独整合的,一个是将它们整合在一起的 ...

  9. SpringBoot集成Spring MVC视图

    SpringBoot在springmvc的视图解析器方面就默认集成了ContentNegotiatingViewResolver和BeanNameViewResolver,在视图引擎上就已经集成自动配 ...

随机推荐

  1. Hbase思维导图之架构

  2. Http 持久连接与 HttpClient 连接池

    一.背景 HTTP协议是无状态的协议,即每一次请求都是互相独立的.因此它的最初实现是,每一个http请求都会打开一个tcp socket连接,当交互完毕后会关闭这个连接. HTTP协议是全双工的协议, ...

  3. vue使用tips记录

    用vue已经很久啦,这里记录一下一些我觉得比较实用的小tips:

  4. synchronized底层实现原理&CAS操作&偏向锁、轻量级锁,重量级锁、自旋锁、自适应自旋锁、锁消除、锁粗化

    进入时:monitorenter 每个对象有一个监视器锁(monitor).当monitor被占用时就会处于锁定状态,线程执行monitorenter指令时尝试获取monitor的所有权,过程如下:1 ...

  5. 51NOD 数字1的数量

    题目描述: 给定一个十进制正整数N,写下从1开始,到N的所有正数,计算出其中出现所有1的个数. 例如:n = 12,包含了5个1.1,10,12共包含3个1,11包含2个1,总共5个1. Input ...

  6. 在Linux安装ASP.NET Core运行时环境

    我使用的是Centos7 ,其它的Linux请参考微软文档   微软官方介绍文档:                                https://www.microsoft.com/n ...

  7. DevExpress VCL 的 cxDBTreeList 的使用方法

    DevExpress VCL 的 cxDBTreeList 的使用方法:(假设控件名为: WBSTree) 1.控件WBSTree 通过绑定  DataSet 获取数据记录(Nodes),通过 Col ...

  8. 一个优秀windows C++ 程序员该有哪些知识

  9. boost--asio--读写大总结

    NO.1 ASIO 读操作大总结: A. Boos::asio::read 同步读方式 void client::read_data(char   * sourse  , int num ) { bo ...

  10. 在 mingw32 上编译 libvpx 1.7.0 时的注意事项

    in the vp8/common/theading.h Just need to add 1 line:#include <sys/types.h>before the last occ ...