SpringBoot集成前端模版(thymeleaf)
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)的更多相关文章
- Spring Boot—06集成前端模板thymeleaf
Spring Boot建议使用这些模板引擎,避免使用JSP,若一定要使用JSP将无法实现Spring Boot的多种特性 pom.xml <dependency> <groupId& ...
- SpringBoot集成Freemarker与Thymeleaf
一:概括 pom.xml添加依赖 配置application.yml HTML页面使用表达式 二:Freemarker模板引擎 1.添加依赖 <!-- ftl模板引擎 --> <de ...
- SpringBoot集成freemarker和thymeleaf模板
1.在MAVEN工程POM.XML中引入依赖架包 <!-- 引入 freemarker 模板依赖 --> <dependency> <groupId>org.spr ...
- 九、SpringBoot集成Thymeleaf模板引擎
Thymeleaf咋读!??? 呵呵,是不是一脸懵逼...哥用我的大学四级英文知识告诉你吧:[θaimlif]. 啥玩意?不会音标?...那你就这样叫它吧:“赛母李府”,大部分中国人是听不出破绽的.. ...
- Springboot 集成 Thymeleaf 及常见错误
Thymeleaf模板引擎是springboot中默认配置,与freemarker相似,可以完全取代jsp,在springboot中,它的默认路径是src/main/resources/templat ...
- springboot集成websocket实现向前端浏览器发送一个对象,发送消息操作手动触发
工作中有这样一个需示,我们把项目中用到代码缓存到前端浏览器IndexedDB里面,当系统管理员在后台对代码进行变动操作时我们要更新前端缓存中的代码怎么做开始用想用版本方式来处理,但这样的话每次使用代码 ...
- SpringBoot集成thymeleaf(自定义)模板中文乱码的解决办法
楼主今天在学习SpringBoot集成thymelaf的时候报了中文乱码的错误,经过网上的搜索,现在得到解决的办法,分享给大家: package com.imooc.config; import or ...
- SpringBoot整合Jsp和Thymeleaf (附工程)
前言 本篇文章主要讲述SpringBoot整合Jsp以及SpringBoot整合Thymeleaf,实现一个简单的用户增删改查示例工程.事先说明,有三个项目,两个是单独整合的,一个是将它们整合在一起的 ...
- SpringBoot集成Spring MVC视图
SpringBoot在springmvc的视图解析器方面就默认集成了ContentNegotiatingViewResolver和BeanNameViewResolver,在视图引擎上就已经集成自动配 ...
随机推荐
- s9.16作业,员工信息表
转载https://blog.csdn.net/qq_35883464/article/details/83151464 实现员工信息表文件存储格式如下:id,name,age,phone,job1, ...
- IActionResult的返回类型
ActionResult继承了IActionResult JsonResult.RedirectResult.FileResult.ViewResult.ContentResult均继承了Action ...
- 新语法11. – LINQ
LINQ分组: IEnumerable<IGrouping< group dog by dog.Age; 遍历分组: foreach (IGrouping<int, Dog> ...
- AtomicLong和LongAdder的区别
AtomicLong的原理是依靠底层的cas来保障原子性的更新数据,在要添加或者减少的时候,会使用死循环不断地cas到特定的值,从而达到更新数据的目的. LongAdder在AtomicLong的基础 ...
- ovs常用操作
1.添加网桥:ovs-vsctl add-br 交换机名 2.删除网桥:ovs-vsctl del-br 交换机名 3.添加端口:ovs-vsctl add-port 交换机名 端口名(网卡名) 4. ...
- pythonのpygame初体验
import pygame import sys from pygame.locals import * #初始化pygame pygame.init() size = width,height=60 ...
- [转] 一文弄懂神经网络中的反向传播法——BackPropagation
在看CNN和RNN的相关算法TF实现,总感觉有些细枝末节理解不到位,浮在表面.那么就一点点扣细节吧. 这个作者讲方向传播也是没谁了,666- 原文地址:https://www.cnblogs.com/ ...
- CF1097F Alex and a TV Show
题目地址:CF1097F Alex and a TV Show bitset+莫比乌斯反演(个人第一道莫比乌斯反演题) 由于只关心出现次数的奇偶性,显然用bitset最合适 但我们并不直接在bitse ...
- LwIP Application Developers Manual4---传输层之UDP、TCP
1.前言 本文主要讲解传输层协议UDP TCP 2.UDP 2.1 UDP from an application perspective 2.2 UDP support history in lwI ...
- Go语言中的map
map是一个集合,可以使用类似处理数组和切片的方式迭代map中的元素.但map是无序的集合.无序的原因是map的实现使用了散列表. map的创建并初始化主要是两种方式: 1.内置的make函数 2.使 ...