1)添加對themeleaf的支持的依賴
<!--Thymeleaf--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
2)在resources的templates目錄下新建currentTime.html
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層的路徑就可以看到頁面效果