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. 6-12mysql库的操作

    1,mysql库的各种分类: nformation_schema: 虚拟库,不占用磁盘空间,存储的是数据库启动后的一些参数,如用户表信息.列信息.权限信息.字符信息等. performance_sch ...

  2. MeEclipse搭建SSH框架之———大体框架

    必备:MyEclipse软件,SSH需要的jar包,数据库,连接数据库的驱动jar包 先搭建大体框架,再加别的东西,要不都不知道哪里错了 一.新建web项目 MyEclipse左边右键--->N ...

  3. DeepLearning.ai-Week3-Autonomous driving-Car detection

    1 - Import Packages import argparse import os import matplotlib.pyplot as plt from matplotlib.pyplot ...

  4. DeepLearning.ai-Week1-Convolution+model+-+Step+by+Step

    1 - Import Packages import numpy as np import h5py import math import matplotlib.pyplot as plt %matp ...

  5. Tesseract识别图片提取文字&字库训练

    文中测试了3.0和4.0两个版本.发现3.0识别效率不准确,需要训练词库.4.0识别效率就比较高了,而且支持结果生成pdf.txt等格式.所以推荐使用4.0版本. 这个工具可以用在爬虫的时候获取验证码 ...

  6. Queue和BlockingQueue的使用以及使用BlockingQueue实现生产者-消费者

    Java提供了两种新的容器类型:Queue和BlockingQueue. Queue用于保存一组等待处理的元素.它提供了几种实现,包括:ConcurrentLinkedQueue,这是一个先进先出的并 ...

  7. 题解-bzoj1283序列 & bzoj4842 [Neerc2016]Delight for a Cat

    因为这两题有递进关系,所以放一起写 Problem bzoj1283 序列 题意概要:一个长度为 \(n\) 的序列\(\{c_i\}\),求一个子集,使得原序列中任意长度为 \(m\) 的子串中被选 ...

  8. vue el-tree:默认展开第几级节点

    需求描述: Tree 树形结构,默认展开第二级菜单. 查 element 文档: 解决方法: 设置  :default-expanded-keys 的值为 idArr 数组, <el-tree ...

  9. iperf 2.05版本升级到2.0.9

    将openwrt  trunk 分支上iperf 2.0.9移植到 bb版本上时,编译遇到如下问题: make[6]: Entering directory '/home/hbg/bb/build_d ...

  10. windows server 2008开启共享文件设置

    之前设置过共享文件,将共享文件映射成磁盘,重新去设置另外服务器的时候,又到网络上找,特此记录 设置网络共享需要开启的服务如下: 以下服务都相关,需要全部开启后才能保证共享正常:1,UPnP Devic ...