1)添加对themeleaf的支持的依赖

 <!--Thymeleaf-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

2)在resources的templates目录下新建currentTime.html

springboot的推荐模板引擎-Thymeleaf

 

th:text的含义是把值显示在当前的标签内

字符串拼接采用双竖||符号就可以

3)修改application.properties,添加如下配置

#thymeleaf 配置
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html
#缓存设置为false,立即生效
spring.thymeleaf.cache=false

 输入controller层的路径就可以看到页面效果

springboot的推荐模板引擎-Thymeleaf

 

相关文章:

  • 2022-01-01
  • 2021-11-17
  • 2021-07-14
  • 2021-05-07
  • 2021-07-14
  • 2022-12-23
猜你喜欢
  • 2021-11-24
  • 2021-11-13
  • 2022-12-23
  • 2021-04-24
  • 2021-12-13
  • 2021-11-19
  • 2021-08-25
相关资源
相似解决方案