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

  • 相关阅读:
    layui table表格 表头与内容列错位问题(只有纵向滚动条的情况)
    layui table+复杂表头+合并单元格
    echarts 柱状图
    1-jdk的安装与配置
    变量的解构赋值(对象)
    变量的解构赋值(数组)
    git常用命令
    markdown常用语法
    微信小程序全局/页面配置
    git使用简介(二)
  • 原文地址:https://www.cnblogs.com/wunaozai/p/8312946.html
Copyright © 2011-2022 走看看