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视图介绍 先看下官网的介绍 ...
随机推荐
- YII2 学习
下载地址: http://www.yiiframework.com/download/ http://www.yiichina.com/download 直接选择basic模板下载即可 下载之后解压到 ...
- 自己动手制作更好用的markdown编辑器-01
这里文章都是从个人的github博客直接复制过来的,排版可能有点乱. 原始地址 http://benq.im 文章目录 1. 简介 2. 项目结构 3. 程序主界面 4. 拖动窗口 5. app ...
- Silverlight实例教程 - Validation服务器端异步数据验证(转载)
摘要:本 篇实例,我们仍旧使用SilverlightValidationDemo项目,为了不和过去的验证方法冲突,这里我们创建一个新的数据成员类 Staff,该类实现INotifyDataErrorI ...
- unity, 由于project settings中time scale变成0导致动画不播放
在Mac和iOS间多次switch platform之后,忽然发现开始scene的动画不播了.进入游戏后再切回来动画恢复正常. 检查了scene的逻辑,发现没有任何问题.删除了Temp和Library ...
- Atitit.创建快捷方式 windows快捷方式的原理
Atitit.创建快捷方式 windows快捷方式的原理 1. Windows中有2种快捷方式的文件:1 2. Jshortcut2 2.1. 提示新不上jshortcut.dll2 2.2. 使用w ...
- 28. Search a 2D Matrix 【easy】
28. Search a 2D Matrix [easy] Write an efficient algorithm that searches for a value in an mx n matr ...
- 键值对集合 dict(字典)
xx= { ss, ss } 创建字典 len(ss) 返回字典到长度,len函数可以返回任何集合的长度,list.tuple.dict都是集合的一种 什么是dict 我们已经知道,list 和 tu ...
- 华为终端开放实验室Android Beta 4测试能力上线
7月26日,Android P Beta 4发布(即Android P DP5),此版本为开发者最后一个预览版本,也预示着Android P正式版即将与大家见面. 为保证开发者在正式版本来临前做 ...
- WebException获取详细内容 记录
http://bbs.csdn.net/topics/390883361 来自此处. 问题.某个接口.返回错误消息用的是400.所以必须知道具体的内容. using System; using Sys ...
- 游戏开发之coco2dx ---简化提炼tolua
http://www.cnblogs.com/gl5773477/p/4234613.html