springboot整合thymeleaf的方法是什么
- 首先,在pom.xml文件中添加Thymeleaf的依赖:
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency>
- 确保在application.properties文件中配置Thymeleaf的模板路径:
spring.thymeleaf.prefix=classpath:/templates/spring.thymeleaf.suffix=.html
- 创建一个Controller类,用于处理页面请求,并返回Thymeleaf模板:
@Controllerpublic class MyController {@RequestMapping("/myPage")public String myPage(Model model) {model.addAttribute("message", "Hello, Thymeleaf!");return "myPage";}}
- 创建一个Thymeleaf模板文件(myPage.html),并在文件中使用Thymeleaf的语法进行页面渲染:
<!DOCTYPE html><html xmlns:th="http://www.thymeleaf.org"><head><title>My Page</title></head><body><h1 th:text="${message}"></h1></body></html>
- 启动Spring Boot应用程序,并访问http://localhost:8080/myPage,即可看到页面上显示"Hello, Thymeleaf!"。
通过以上步骤,就可以实现Spring Boot整合Thymeleaf的功能。
上一篇:r语言自动运行代码怎么配置
下一篇:Java中scheduledexecutorservice是什么
SpringBoot thymeleaf
声卡驱动正常但是没有声音如何办?声卡驱动正常没声音的解决方法
英伟达显卡驱动如何退回到原来版本?英伟达显卡驱动退回到原来版
重装系统,电脑只有一个C盘如何创建分区
Defender提示错误应用程序MsMpEng.exe无法启动
电脑无法启动或仍在加载如何办?电脑无法启动或仍在加载的解决方
打印机驱动如何卸载删除?卸载打印机驱动干净的教程
电脑没网如何安装网卡驱动?教你没网如何安装网卡驱动的方法
系统32位和62位如何选择:详解它们之间的差异
电脑文件删不掉如何办?四种方法解决
任务管理器快捷键有哪些?任务管理器快捷键大全