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. JAVA进阶3

    间歇性混吃等死,持续性踌躇满志系列-------------第3天 1.局部内部类 局部内部类是指在类的方法中定义的内部类,它的作用范围也是在这个方法体内. class SellOutClass{ p ...

  2. 基于netty实现单聊、群聊功能

    学习资料 https://juejin.im/book/5b4bc28bf265da0f60130116/section/5b6a1a9cf265da0f87595521 收获: 转载 1. Nett ...

  3. 添加,删除List<Map<String, Object>>元素

    这里讲对List<Map<String, Object>>的数据结构的添加和删除实例 添加 //初始化 List<Map<String, Object>> ...

  4. Python概念(八)字符串格式化:%和.format

    https://www.cnblogs.com/nulige/p/6115793.html

  5. L - LCM Walk HDU - 5584 (数论)

    题目链接: L - LCM Walk HDU - 5584 题目大意:首先是T组测试样例,然后给你x和y,这个指的是终点.然后问你有多少个起点能走到这个x和y.每一次走的规则是(m1,m2)到(m1+ ...

  6. spring4 注入参数

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  7. C++ 11 snippets , 2

    <1>auto ,initializer_list<T>,auto指向函数指针的简易,和typdef 定义的类型执行函数指针有多复杂. #include <iostrea ...

  8. Python3-高阶函数、闭包

    一.高阶函数   满足下列条件之一为高阶函数 1.某一函数当作参数传入另一个函数中 2.函数的返回值包含n个函数,n>0 高阶函数示范: def bar(): print 'in the bar ...

  9. BIM 开发商 --广州

    BIM 开发或咨询商 --广州: 1.广州君和信息技术有限公司(与二公司有合作,推荐!)  艾三维软件 www.i3vsoft.com  广州市越秀区东风中路445号越秀城市广场北塔2007 是一家为 ...

  10. 在windows下用vagrant建立lnmp开发环境

    1.安装vagrant,vitrualbox 2.下载homestead的box包,并添加到vagrant 下载地址: https://atlas.hashicorp.com/laravel/boxe ...