SpringBoot使用Thymeleaf模板引擎访问静态html的过程
作者:刘弘扬fine 时间:2023-11-25 10:04:44
最近要做一个java web项目,因为页面不是很多,所以就没有前后端分离,前后端写在一起,这时候就用到thymeleaf了,以下是不动脑式的傻瓜教程。。。。。
一:创建spring boot的web项目,过程略;
二:依赖如下:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
三:配置文件:application.properties
#端口号
server.port=8099
# 配置
#thymeleaf
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.check-template-location=true
spring.thymeleaf.suffix=.html
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.mode=HTML
四:项目的templates文件夹下新建页面success.html,如下
五:controller
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @author liuhongyang
* @2020/10/20 14:35
* 文件说明:
*/
@Controller
public class FirstTestController {
@RequestMapping(value = "hello")
public String hello(ModelMap modelMap) {
modelMap.put("hei", "thymeleaf");
return "success";
}
}
六:访问如下,完成
来源:https://blog.csdn.net/qq_35101267/article/details/109181638
标签:SpringBoot,Thymeleaf,静态html
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SpringBoot中属性赋值操作的实现
2022-05-04 18:10:30
![](https://img.aspxhome.com/file/2023/3/70943_0s.png)
Java多线程wait()和notify()方法详细图解
2021-09-19 20:27:32
![](https://img.aspxhome.com/file/2023/1/66231_0s.png)
C#实现最完整的文件和目录操作类实例
2022-05-19 09:38:51
Java链表中元素删除的实现方法详解【只删除一个元素情况】
2023-01-16 11:49:41
![](https://img.aspxhome.com/file/2023/3/68693_0s.png)
Android自定义View实现遥控器按钮
2021-12-27 09:50:47
![](https://img.aspxhome.com/file/2023/5/125525_0s.gif)
Python代码一键转Jar包及Java调用Python新姿势
2023-02-13 08:16:22
![](https://img.aspxhome.com/file/2023/4/96944_0s.jpg)
Idea springboot springCloud热加载热调试两种常用方式
2021-06-11 22:20:06
![](https://img.aspxhome.com/file/2023/3/122953_0s.png)
Java实现的求逆矩阵算法示例
2023-05-02 03:02:56
![](https://img.aspxhome.com/file/2023/2/76512_0s.jpg)
c# 将Datatable数据导出到Excel表格中
2023-12-26 02:03:53
手动编译C#代码的方法
2021-05-27 05:42:40
![](https://img.aspxhome.com/file/2023/1/91381_0s.png)
分析Java设计模式之组合模式
2023-11-25 13:13:30
![](https://img.aspxhome.com/file/2023/6/59856_0s.jpg)
Java利用apache ftp工具实现文件上传下载和删除功能
2022-03-17 02:04:01
Java二维数组计算集合总结
2023-02-15 16:38:14
![](https://img.aspxhome.com/file/2023/8/63998_0s.jpg)
Android WebView实现网页滚动截图
2022-12-12 12:13:03
![](https://img.aspxhome.com/file/2023/8/88098_0s.jpg)
Android studio开发实现计算器功能
2022-02-12 19:43:05
![](https://img.aspxhome.com/file/2023/1/125521_0s.jpg)
Android开发使用RecyclerView添加点击事件实例详解
2022-04-30 14:11:55
对Java ArrayList的自动扩容机制示例讲解
2022-04-09 07:58:25
Jetpack Compose常用组件详细介绍
2022-10-16 19:42:58
![](https://img.aspxhome.com/file/2023/4/90134_0s.png)
Android实现中轴旋转特效 Android制作别样的图片浏览器
2023-07-03 00:37:16
![](https://img.aspxhome.com/file/2023/2/104662_0s.png)
C# 程序集和反射详解
2022-12-29 20:24:18
![](https://img.aspxhome.com/file/2023/7/111267_0s.png)