前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >Spring boot with Thymeleaf

Spring boot with Thymeleaf

作者头像
netkiller old
发布于 2018-03-06 02:43:03
发布于 2018-03-06 02:43:03
93500
代码可运行
举报
文章被收录于专栏:NetkillerNetkiller
运行总次数:0
代码可运行
本文节选自电子书《Netkiller Java 手札》

5.19. Spring boot with Thymeleaf

5.19.1. Maven

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
	<dependency>  
		<groupId>org.springframework.boot</groupId>  
		<artifactId>spring-boot-starter-thymeleaf</artifactId>  
	</dependency>			

5.19.2. application.properties

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.prefix=/WEB-INF/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false	

5.19.3. Controller

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package cn.netkiller.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/")
public class HelloController {

	@RequestMapping(value = "/{name}", method = RequestMethod.GET)
	public String getMovie(@PathVariable String name, ModelMap model) {
		model.addAttribute("name", name);
		return "hello";
	}

}			

5.19.4. HTML5 Template

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Spring MVC + Thymeleaf Example</title>
</head>
<body>
	Hello, <span th:text="${name}" />!
</body>
</html>	
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2017-11-09,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Netkiller 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
Spring Boot 集成 Thymeleaf 模板
2. application.properties 文件中添加 Thymeleaf 模板配置
北漂的我
2019/05/29
4730
SpringBoot入门系列(四)整合Thymeleaf模板引擎
这个系列课程的完整源码,也会提供给大家。大家关注我的微信公众号(架构师精进),回复:springboot源码 获取这个系列课程的完整源码。或者点此链接直接下载完整源码
架构师精进
2020/03/19
6810
SpringBoot入门系列(四)整合Thymeleaf模板引擎
springboot (二) thymeleaf
前言: thymeleaf 是由thyme taIm ,leafli:f两个单词组成. thymeleaf 是java模版引擎,可以很好的和spring集成。 1.引入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> 2.application.properties中添加配置 spri
IT架构圈
2018/06/01
6390
Spring Boot 整合 Thymeleaf
第 2.3 中,设置了跳转的视图为 index,所以我们需要在 src/main/resources/templates 中创建 index.html;
村雨遥
2020/08/04
5350
Spring Boot 整合 Thymeleaf
Spring Boot 与 kotlin 使用Thymeleaf模板引擎渲染web视图
在我们开发Web应用的时候,需要引用大量的js、css、图片等静态资源,使用Spring Boot 与 kotlin如何去支持这些静态资源?,很简单。
全科
2018/08/15
1.5K0
spring boot 登录注册 demo (一)
Welcome to Spring Boot 代码结构 src/main/java 下 controller层,路由功能 dao层,数据库的访问 domain,bean的存放 service,业务层
千往
2018/01/24
1.5K0
spring boot 登录注册 demo (一)
Spring Boot 整合 Thymeleaf 完整 Web 案例
摘要: 原创出处:www.bysocket.com 泥瓦匠BYSocket 希望转载,保留摘要,谢谢!
二哥聊运营工具
2021/12/17
1.8K0
Spring Boot 整合 Thymeleaf 完整 Web 案例
SpringBoot整合thymeleaf
引入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> 我们的boot的starter已经整合过了,不需要版本坐标。 创建 创建一个HTML文件。 我们需要再<html>标签里面加点东西。 运行 我直接打开这个html时,他是这样的。 因为我们需要web服务对thymelea
JanYork_简昀
2022/10/05
1680
SpringBoot整合thymeleaf
Spring Cloud 2.x系列之模板引擎thymeleaf
相对html+js的传统设计,现在很多网站都采用div&css+标签化+模块化的设计。模板引擎根据一定的语义,将数据填充到模板中,产生最终的HTML页面。模板引擎主要分两种:客户端引擎和服务端引擎。
BUG弄潮儿
2022/06/30
7640
Spring Cloud 2.x系列之模板引擎thymeleaf
spring boot用ModelAndView向Thymeleaf模板传参数
最近在调试一个Spring Boot向Thymeleaf模板传参数的例子,但踩了很多坑,这里就把详细过程记录下来,以供大家参考。
用户1153489
2021/03/02
3K1
Spring Boot —— Thymeleaf + Gradle run on Tomcat(war形式)
Spring Boot 以Jar的方式部署启动,这个不用介绍了, 之前也介绍了关于 Spring Boot + thymeleaf 的简单使用 ,但是今天遇到一个问题, 我先描述下问题的场景:
执笔记忆的空白
2020/12/25
8660
Spring Boot---(16)Spring Boot使用Thymeleaf开发web页面
摘要:Spring官方不推荐使用JSP来开发WEB,而是推荐使用如下几种模板引擎来开发:
IT云清
2019/01/22
6030
SpringBoot集成Thymeleaf模板
1 创建一个maven工程,这个应该都会 2 pom文件加入下面内容即可(版本号自己改 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.4.RELEASE</version> <relativePath/> <!-- lookup parent fro
JavaEdge
2018/04/28
7370
springboot使用thymeleaf为模板
jsp已经明显跟不上时代发展了,freemarker用的够够的?换thymeleaf试试吧。springboot官方推荐的是freemarker和thymeleaf,而thymeleaf相对于freemarker更让人感觉强大的,是他可以动态替换标签内静态内容,这样前端可以安心写页面,后台可以安心撸接口,只需要把变量替换一下即可,这种理念,不知道是VUE抄袭了thymeleaf还是thymeleaf抄袭了VUE,不过无所谓了 ,对于我们广大码奴来说,实用就好
小尘哥
2018/08/15
5050
springboot使用thymeleaf为模板
(12)SpringBoot使用Thymeleaf开发web页面
   摘要:本文主要讲解SpringBoot使用Thymeleaf开发web页面。
IT云清
2022/05/07
7050
(12)SpringBoot使用Thymeleaf开发web页面
Spring Boot 集成Thymeleaf
thymeleaf 语法——input、select、radio、textarea 回显
HLee
2021/03/09
2.2K0
Spring Boot 集成Thymeleaf
SpringBoot-04-之模板引擎--thymeleaf
一.前期工作 1.添加依赖 <!--thymeleaf引擎模板--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> 2.thymeleaf 静态资源配置:src\main\resources\application-dev.yml #默认 spring.thymeleaf.prefi
张风捷特烈
2018/09/26
5420
Spring Boot入门教程3-2、使用Spring Boot+Thymeleaf模板引擎开发Web应用
在最早的Java Web应用中,最为广泛使用的就是JSP,但是JSP已经是陈旧的技术了,ken.io觉得JSP主要有三个问题: 1、视图代码不能与Java代码完全分离,如果再JSP页面写Java代码维护成本高 2、无法实现页面继承工程,实现模板页的方式蹩脚 3、由于一些已知问题,Spring Boot官方不建议,比如:Spring Boot+JSP打成jar包会有问题
KenTalk
2018/09/11
9990
SpringBoot之thymeleaf
1.添加thymeleaf的jar包依赖 <!-- thymeleaf --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> <exclusions> <exclusion>
王念博客
2019/07/25
3740
SpringBoot静态化
src/main/resources/templates/*.html,默认是从templates文件夹里找html资源。
南风
2019/04/22
1.2K0
SpringBoot静态化
相关推荐
Spring Boot 集成 Thymeleaf 模板
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验