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
Copyright © 2002-2019 测速网 www.inhv.cn 皖ICP备2023010105号
测速城市 测速地区 测速街道 网速测试城市 网速测试地区 网速测试街道
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!

热门搜索 城市网站建设 地区网站制作 街道网页设计 大写数字 热点城市 热点地区 热点街道 热点时间 房贷计算器