1. pom.xml依赖添加

    1.  <!--引入thymeleaf-->
      <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-thymeleaf</artifactId>
      </dependency> <!--引入谷歌的guava-->
      <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>19.0</version>
      </dependency> <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      </dependency>
  2. yml的配置  

    1.  spring:
      thymeleaf:
      cache: true
      check-template: true
      check-template-location: true
      encoding: utf-8
      prefix: classpath:/templates/
      servlet:
      content-type: text/html
      suffix: .html
  3. 实体类的创建 

    1.  @Data
      @AllArgsConstructor
      public class Book {
      private Integer id;
      private String name;
      private String author;
      }
  4. controller层

    1.  @Controller
      public class BookController {
      @GetMapping("/book")
      public ModelAndView book(){
      ModelAndView mv = new ModelAndView();
      // 谷歌的guava 集合方法
      List<Book> mybook = Lists.newArrayList(new Book(1,"小李子","小明"),
      new Book(2,"小乌龟","挽歌"));
      mv.addObject("mybook",mybook);
      mv.setViewName("books");
      return mv;
      }
      }
  5. html视图  

    1.  <!DOCTYPE html>
      <html lang="en" xmlns:th="http://www.thymeleaf.org">
      <html lang="en">
      <head>
      <meta charset="UTF-8">
      <title>图书列表</title>
      </head>
      <body>
      <table border="1">
      <tr>
      <td>图书编号</td>
      <td>图书名称</td>
      <td>图书作者</td>
      </tr>
      <tr th:each="book:${mybook}">
      <td th:text="${book.id}"></td>
      <td th:text="${book.name}"></td>
      <td th:text="${book.author}"></td>
      </tr>
      </table>
      </body>
      </html>
    2. templates->xxx.html

  6. 启动项目(http://localhost:8080/book)

springboot 整合thymeleaf 书笔记的更多相关文章

  1. SpringBoot 整合 Thymeleaf & 如何使用后台模板快速搭建项目

    如果你和我一样,是一名 Java 道路上的编程男孩,其实我不太建议你花时间学 Thymeleaf,当然他的思想还是值得借鉴的.但是他的本质在我看来就是 Jsp 技术的翻版(Jsp 现在用的真的很少很少 ...

  2. SpringBoot 整合thymeleaf

    1.Thymeleaf介绍(官网推荐:https://www.thymeleaf.org/doc/articles/thymeleaf3migration.html) Thymeleaf是跟Veloc ...

  3. 【Springboot】Springboot整合Thymeleaf模板引擎

    Thymeleaf Thymeleaf是跟Velocity.FreeMarker类似的模板引擎,它可以完全替代JSP,相较与其他的模板引擎,它主要有以下几个特点: 1. Thymeleaf在有网络和无 ...

  4. Springboot整合thymeleaf模板

    Thymeleaf是个XML/XHTML/HTML5模板引擎,可以用于Web与非Web应用. Thymeleaf的主要目标在于提供一种可被浏览器正确显示的.格式良好的模板创建方式,因此也可以用作静态建 ...

  5. 三、SpringBoot整合Thymeleaf视图

    目录 3.1 Thymeleaf视图介绍 3.2 创建SpringBoot项目 3.2 配置Thymeleaf 3.3 编写Demo 3.4 小结 3.1 Thymeleaf视图介绍 先看下官网的介绍 ...

  6. springboot整合thymeleaf+tiles示例

    网上关于此框架的配置实在不多,因此想记录下来以防忘记 因为公司框架基于上述(公司采用gradle构建项目,楼主采用的是maven),所以楼主能少走些弯路: 1.创建springboot-maven项目 ...

  7. SpringBoot:2.SpringBoot整合Thymeleaf模板引擎渲染web视图

    在Web开发过程中,Spring Boot可以通过@RestController来返回json数据,那如何渲染Web页面?Spring Boot提供了多种默认渲染html的模板引擎,主要有以下几种: ...

  8. SpringBoot整合EHcache学习笔记

    为了提高系统的运行效率,引入缓存机制,减少数据库访问和磁盘IO.下面说明一下ehcache和SpringBoot整合配置 前言介绍 EhCache 是一个纯Java的进程内缓存框架,具有快速.精干等特 ...

  9. springboot整合Thymeleaf模板引擎

    引入依赖 需要引入Spring Boot的Thymeleaf启动器依赖. <dependency> <groupId>org.springframework.boot</ ...

随机推荐

  1. PAT Advanced 1155 Heap Paths (30) [DFS, 深搜回溯,堆]

    题目 In computer science, a heap is a specialized tree-based data structure that satisfies the heap pr ...

  2. WordPress站点绑定多个域名

    refer to https://blog.csdn.net/wzl505/article/details/54970321 打开根目录下的 wp-config.php 文件,找到 require_o ...

  3. python----linux下简单的排序

    1.选择排序:把一个数与余下所有的数排序,最小的排到最前面 [root@besttest liyn_test]# cat test.py #! /usr/bin/python a=[,,,] ,len ...

  4. Java算法练习——两数之和

    题目链接 题目描述 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,你不能重复利 ...

  5. CMakeLists添加内部库

    SET(RTABMap_LIBRARIES ${PROJECT_SOURCE_DIR}/bin/librtabmap_core.so ${PROJECT_SOURCE_DIR}/bin/librtab ...

  6. filter的原理(转)

    今天学习了一下javaweb开发中的Filter技术,于是在网上搜了一下相关资料,发现这篇博客写的很不错,于是希望能转载过来以备以后继续学习之用.(原:http://www.cnblogs.com/x ...

  7. UVA 11922 伸展树Splay 第一题

    上次ZOJ月赛碰到一个题目要求对序列中的某个区间求gcd,并且还要随时对某位数字进行修改 插入 删除,当时马上联想到线段树,但是线段树不支持增删,明显还是不可以的,然后就敲了个链表想暴力一下,结果TL ...

  8. 在excel中评估模型性能

    一直在用的结果, 从代码中整理出来. 评分卡模型的结果一般在excel中即可计算完成. 下面是在number中计算评分卡模型的性能(KS/AUC), 表格中百分数省略%

  9. 04-for循环的各个语句及list列表学习

    目录 04-for循环的各个语句及list列表学习 1. for循环 2. range()函数 3. 循环语句中的break.continue.pass 4. list列表 5. 列表生成式 6. 实 ...

  10. JDK的3个bug啊,你get到了吗?

    1.Annotation引用非空enum数组返回空数组 首次发现时的环境:JDK 1.8 首次发现所在项目:APIJSON 测试用例: publicenumRequestRole {/**未登录,不明 ...