springboot整合 Thymeleaf模板
首先引入maven jar依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
接着在application.properties内配置 thymeleaf
#设置thymeleaf 注意:一定要在web后面添加一个 斜杠 /,否则找不到文件
spring.thymeleaf.prefix=classpath:/web/
spring.thymeleaf.suffix=.html
#设置thymeleaf不按照HTML5严格的检查标签
spring.thymeleaf.mode=LEGACYHTML5
模板默认还是放在templates文件夹下,这里我修改到web文件夹下面了

package com.example.demo.controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import com.example.demo.entity.Student; @Controller
@RequestMapping("/student/")
public class StudentController { @RequestMapping("show")
public String show(Model model) { Student stu = new Student();
stu.setId(1001);
stu.setName("小明");
model.addAttribute("student", stu); model.addAttribute("str", "this is spring boot freemarker");
return "show";
} }
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>thymeleaf</h1>
<h3 th:text="${str}">h3</h3>
id:<span th:text="${student.id}"></span><br>
name:<span th:text="${student.name}"></span>
</body>
</html>
springboot整合 Thymeleaf模板的更多相关文章
- Springboot整合thymeleaf模板
Thymeleaf是个XML/XHTML/HTML5模板引擎,可以用于Web与非Web应用. Thymeleaf的主要目标在于提供一种可被浏览器正确显示的.格式良好的模板创建方式,因此也可以用作静态建 ...
- 【Springboot】Springboot整合Thymeleaf模板引擎
Thymeleaf Thymeleaf是跟Velocity.FreeMarker类似的模板引擎,它可以完全替代JSP,相较与其他的模板引擎,它主要有以下几个特点: 1. Thymeleaf在有网络和无 ...
- springboot整合Thymeleaf模板引擎
引入依赖 需要引入Spring Boot的Thymeleaf启动器依赖. <dependency> <groupId>org.springframework.boot</ ...
- SpringBoot:2.SpringBoot整合Thymeleaf模板引擎渲染web视图
在Web开发过程中,Spring Boot可以通过@RestController来返回json数据,那如何渲染Web页面?Spring Boot提供了多种默认渲染html的模板引擎,主要有以下几种: ...
- (二)springboot整合thymeleaf模板
在我们平时的开发中,用了很久的jsp作view显示层,但是标签库和JSP缺乏良好格式的一个副作用就是它很少能够与其产生的HTML类似.所以,在Web浏览器或HTML编辑器中查看未经渲染的JSP模板是非 ...
- 3.SpringBoot整合Thymeleaf模板
一.前言 SrpingBoot支持如JSP.Thymeleaf.FreeMarker.Mustache.Velocity等各种模板引擎,同时还为开发者提供了自定义模板扩展的支持. 使用嵌入式Servl ...
- SpringBoot 整合 Thymeleaf & 如何使用后台模板快速搭建项目
如果你和我一样,是一名 Java 道路上的编程男孩,其实我不太建议你花时间学 Thymeleaf,当然他的思想还是值得借鉴的.但是他的本质在我看来就是 Jsp 技术的翻版(Jsp 现在用的真的很少很少 ...
- springboot整合thymeleaf+tiles示例
网上关于此框架的配置实在不多,因此想记录下来以防忘记 因为公司框架基于上述(公司采用gradle构建项目,楼主采用的是maven),所以楼主能少走些弯路: 1.创建springboot-maven项目 ...
- 三、SpringBoot整合Thymeleaf视图
目录 3.1 Thymeleaf视图介绍 3.2 创建SpringBoot项目 3.2 配置Thymeleaf 3.3 编写Demo 3.4 小结 3.1 Thymeleaf视图介绍 先看下官网的介绍 ...
随机推荐
- Xilinx 7系列例化MIG IP core DDR3读写
昨晚找了一下,发现DDR3读写在工程上多是通过例化MIG,调用生成IPcore的HDL Functional Model.我说嘛,自己哪能写出那么繁琐的,不过DDR读写数据可以用到状态机,后期再添砖加 ...
- 661. Image Smoother【easy】
661. Image Smoother[easy] Given a 2D integer matrix M representing the gray scale of an image, you n ...
- 李洪强-HEAD 和nil和NULL
- centos7下安装mysql5.7和jdk 1.8
安装mysql5.7 具体安装过程可参见官网:A Quick Guide to Using the MySQL Yum Repository 进入/usr/local/src文件夹. cd /usr/ ...
- Java(System类,currentTimeMillis())
CurrentTimeMillis()方法来记录程序的执行时间.currentTimeMillis()方法将返回自1970年1月1日午夜起到现在的时间,时间单位是ms,如果要记录程序中一段程序的运行时 ...
- 消息队列(message queue)
最近纠结于一个问题,就是horizon 在处理前台数据的时候非得等到cinder client将数据全部获取后才开始执行horizon的下一行代码,这给大量数据显示造成了很大的时延,其实对于用户体验来 ...
- ios [__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x7a97d4c0'报错
今天接口由get换成post,我去改进行登录但出现了这个错误,首先出错先看能不能与服务器交互,能不能获得数据,其次,获得的数据是不是你想要的,记住,首先出错要想到是自己的问题,还有就是程序崩了要学会自 ...
- 现代 PHP 新特性系列
生成器的创建和使用 http://laravelacademy.org/post/4317.html
- 排序算法 c实现
c语言实现插入排序.冒泡排序.选择排序.快速排序.堆排序.归并排序.希尔排序示例,需要的朋友可以参考下 实现以下排序 插入排序O(n^2) 冒泡排序 O(n^2) 选择排序 O(n^2) 快速 ...
- 在看lua仿单继承
--lua仿单继承 Account = { balance = } --对于成员变量,第一此访问要使用元表中的,在第一次也赋值到自己的域中了 --将不涉及到__index了 function Acco ...