zoukankan      html  css  js  c++  java
  • 物联网架构成长之路(14)-SpringBoot整合thymeleaf

      使用thymeleaf作为模版进行测试
      在pom.xml 增加依赖

    1 <dependency>
    2     <groupId>org.springframework.boot</groupId>
    3     <artifactId>spring-boot-starter-thymeleaf</artifactId>
    4 </dependency>

      在application.properties中进行配置

    1 #thymeleaf start
    2 spring.thymeleaf.mode=HTML5
    3 spring.thymeleaf.encoding=UTF-8
    4 spring.thymeleaf.content-type=text/html
    5 #开发时关闭缓存,不然没法看到实时页面
    6 spring.thymeleaf.cache=false
    7 spring.thymeleaf.prefix=classpath:/templates/
    8 spring.thymeleaf.suffix=.html
    9 #thymeleaf end

      在 src/main/resources 下新建 templates 目录 并创建 hellohtml.html 文件

     1 <!DOCTYPE html>  
     2 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"  
     3       xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">  
     4     <head>  
     5         <title>Hello World!</title>  
     6     </head>  
     7     <body>  
     8         <h1 th:inline="text">Hello.v.2</h1>  
     9         <p th:text="${hello}"></p>  
    10     </body>  
    11 </html> 

      增加Controller

    1 @Controller
    2 @RequestMapping("/html")
    3 public class ThymeleafController {
    4     @RequestMapping("/hellohtml")
    5     public String helloHtml(Map<String, Object> map) {
    6         map.put("hello", "from TemplateController.helloHtml");
    7         return "/hellohtml";
    8     }
    9 }

      预览看效果

      关于thymeleaf更多的语法这里就不展开说了。

  • 相关阅读:
    牛客noip前集训营(第一场)提高T1
    约数的个数
    牛客OI赛制测试赛2 D 星光晚餐
    牛客OI赛制测试赛2 C 数组下标
    牛客OI赛制测试赛2 A 无序组数
    [题解] codevs 1486 愚蠢的矿工
    字典(trie)树--从入门到入土
    [题解] cogs 2240 架设电话线路
    [题解] cogs 1669 神秘的咒语
    LCIS 最长上升公共子序列问题
  • 原文地址:https://www.cnblogs.com/wunaozai/p/8312946.html
Copyright © 2011-2022 走看看