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更多的语法这里就不展开说了。

  • 相关阅读:
    linux awk命令详解
    世界上最差的系统就是linux,双击不能安装软件
    硬盘安装CentOS 6.0(超级详细图文教程)
    Vim+cscope+ctags+tags阅读源代码
    使用vim看代码:cscope
    解决面板里没有network manager图标的问题
    【b804】双栈排序
    【BZOJ 1002】[FJOI2007]轮状病毒
    【BZOJ 1004】 [HNOI2008]Cards
    【t018】派对
  • 原文地址:https://www.cnblogs.com/wunaozai/p/8312946.html
Copyright © 2011-2022 走看看