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. vue之v-for循环的使用

  2. LOJ #2587「APIO2018」铁人两项

    是不是$ vector$存图非常慢啊...... 题意:求数对$(x,y,z)$的数量使得存在一条$x$到$z$的路径上经过$y$,要求$x,y,z$两两不同  LOJ #2587 $ Solutio ...

  3. ASCII字符集。扩展ASCII字符集。Unicode字符集分别支持多少个字符?

    ASCII字符集.扩展ASCII字符集.Unicode字符集分别支持多少个字符? 256个字符和 65536个字符

  4. HTML - HTML基础篇

    一.什么是html ? 超文本标记语言.HTML 是标记语言 历史版本: Html 4.01 1999年12月24日,w3c推荐标准 (老网站) 如今 是 html 5 版本. 1.Html 标签拥有 ...

  5. 关于vue监听dom与传值问题

    1. 代码初始化一次执行部分属性为空的情况 原因: 异步加载 + 立马 传值时 直接渲染 dom里面  能实时更新 (无影响) 不能直接dom中渲染(有影响)     解决方法:需要通过监听的方式来处 ...

  6. shell编程 之 输入输出重定向

    1 输入输出重定向 标准输入:从终端得到命令,对于计算机来说,是从终端获得了命令,执行完了以后,结果和执行状态或者错误提示又会发回终端,这叫标准输出. 输入输出重定向就是从终端以外的别的地方得到输入, ...

  7. springboot整合JSP以及发布项目到独立的tomcat中与打成jar包使用

    之前研究了springboot整合freemarker与thymeleaf的使用.也研究了springboot发布到独立的tomcat的使用以及使用自带的tomcat打成jar包的使用,下面研究集成J ...

  8. PHP反序列化漏洞学习

    serialize:序列化 unserialize: 反序列化 简单解释: serialize 把一个对象转成字符串形式, 可以用于保存 unserialize 把serialize序列化后的字符串变 ...

  9. python的MySQLdb库链接MySQL入门代码

    链接:http://www.runoob.com/python/python-mysql.html

  10. 负载均衡获得真实源IP的6种方法 【转】

    除了X-FORWARD-FOR,负载均衡中获得真实源IP的方法还有很多种, 本文抛砖引玉,主要介绍获得真实源IP的多种方法,而不是具体配置, 负载均衡获得真实IP的方法有很多种,将形成专题文章, 本文 ...