前言
上一节使用了"过时"的jsp技术,这一节我们来使用springboot推荐的模板thymeleaf技术。
创建项目
使用IDEA创建springboot项目,直接勾选web和thymeleaf依赖
查看依赖
添加配置
application.yml:
spring:
thymeleaf:
mode: HTML5
encoding: UTF-8
##关闭缓存
cache: false
添加模板
在resources的templates下创建index.html:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout">
<head>
<meta charset="utf-8"/>
</head>
<body>
<span th:text="'yes, ' + ${name} + '!'"></span>
</body>
</html>
注意,这里模板内注入了个变量"name",模板都是使用"${变量名}"这种方式注入变量的。
完善
目录结构
controller/IndexController:
package com.mrcoder.sbthymeleaf.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class IndexController {
@RequestMapping(value = "/")
public String index(Model model){
//注入name变量到模板
model.addAttribute("name", "hello world");
return "index";
}
}
访问
关于thymeleaf的更多语法请自行去看官方文档哦。
项目地址
https://github.com/MrCoderStack/SpringBootDemo/tree/master/sb-thymeleaf
https://gitee.com/MrCoderStack/SpringBootDemo/tree/master/sb-thymeleaf
请关注我的订阅号
转载于:https://my.oschina.net/u/3066875/blog/3055369
分享到:
相关推荐
java运行依赖jar包
课程内容在以往SpringBoot案例课程之上,再次加深了难度和深度,直接对标一线大厂的高级应用实践。课程围绕着SpringBoot开发实践和SpringBoot高级应用两个主题展开,是真正意义上...├─SpringBoot-ThymeLeaf-Book.rar
springboot整合thymeleaf模板
## springboot整合thymeleaf ### 1. 导入起步依赖 ```xml <groupId>org.springframework.boot <artifactId>spring-boot-starter-thymeleaf ``` ### 2. 更改引入版本 ```xml <springboot-thymeleaf.version...
SpringBoot中整合Thymeleaf示例代码
基于SpringBoot+thymeleaf+mybatis构建的旅游后台管理系统,课程设计,毕业设计 基于SpringBoot的旅游后台管理系统 1. 技术栈 springboot mybatis-plus thymeleaf 2. 功能 注册用户管理 旅游线路分类管理 旅行社管理...
maven-springboot-mysql-thymeleaf-mybatis-CRUD增删改查完整版
演示如何整合 springboot 1.2.0 + thymeleaf 2.x + tiles 2.2.2, boot部分主要以spring mvc为主。 使用前先准备好maven3.x环境。
Springboot-Mybatis-thymeleaf实现简单的注册登录,增删查改功能。
赠送jar包:thymeleaf-extras-java8time-3.0.4.RELEASE.jar; 赠送原API文档:thymeleaf-extras-java8time-3.0.4.RELEASE-javadoc.jar; 赠送源代码:thymeleaf-extras-java8time-3.0.4.RELEASE-sources.jar; 赠送...
赠送jar包:thymeleaf-extras-java8time-3.0.1.RELEASE.jar; 赠送原API文档:thymeleaf-extras-java8time-3.0.1.RELEASE-javadoc.jar; 赠送源代码:thymeleaf-extras-java8time-3.0.1.RELEASE-sources.jar; 赠送...
Springboot整合Hibernate thymeleaf,添删改查,分页查询等,单元测试,亲测百分之百可运行,网上好多功能不全,甚至无法运行,这个是我自己亲自跑的,绝对没有问题
虾米大王教你学编程 Springboot从入门到实战-03-整合Thymeleaf(三)
1、基于SpringBoot+Mybatis+Thymeleaf实现的BBS论坛系统源码.zip 2、该资源包括项目的全部源码,下载可以直接使用! 3、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为参考资料...
springboot-thymeleaf-activiti-master java工作流设计
运用SpringBoot框架搭建项目,thymeleaf渲染前端数据,重点在于SpringBoot和thymeleaf的学习
图书管理系统(SpringBoot,thymeleaf).zip图书管理系统(SpringBoot,thymeleaf).zip图书管理系统(SpringBoot,thymeleaf).zip图书管理系统(SpringBoot,thymeleaf).zip图书管理系统(SpringBoot,thymeleaf).zip图书管理...
1、基于SpringBoot+Thymeleaf+JPA的博客系统源码.zip 2、该资源包括项目的全部源码,下载可以直接使用! 3、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为参考资料学习借鉴。 ...
【资源说明】 1、该资源包括项目的全部源码,下载可以直接使用! 2、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设...基于Java+SpringBoot及thymeleaf的疫情信息管理系统源码+项目说明.zip
springboot-2.0.1整合jsp博客地址:https://blog.csdn.net/qq_35161159/article/details/102978086