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. SASS - 混合(Mixin)

    SASS – 简介 SASS – 环境搭建 SASS – 使用Sass程序 SASS – 语法 SASS – 变量 SASS- 局部文件(Partial) SASS – 混合(Mixin) SASS ...

  2. JavaWeb之监听器

    1. 介绍         监听器是一个专门用于对其他对象身上发生的事件或状态改变进行监听和相应处理的对象,当被监视的对象发生情况时,立即采取相应的行动.监听器其实就是一个实现特定接口的普通java程 ...

  3. 洛谷 P5662 纪念品

    题目传送门 解题思路: 一道DP,完全背包,不过有点不同于模板.因为本题的每件物品可自由在不同的时间买卖,且不同时间价格不同. 这道题的关键在于要明白一个非常傻逼的性质,就是我在某天买了第i个物品,然 ...

  4. 理解String的intern()方法

    API文档中的介绍: intern public String intern() Returns a canonical representation for the string object. A ...

  5. 第一个eclipse maven项目!我超全!

    前言:以前一直用idea做东西,今天突然想试一下,没想到配置起来是真的麻烦!!!!会出现各种各样的问题,太晚了,本文只做出几处非常严重的问题,如有疑问,请私信,留言 准备:本文     JDK 1.8 ...

  6. [mysql8 报错] 关闭ONLY_FULL_GROUP_BY

    bug原因: 对于GROUP BY聚合操作,如果在SELECT中的列,没有在GROUP BY中出现,那么这个SQL是不合法的,因为列不在GROUP BY从句中.简而言之,就是SELECT后面接的列必须 ...

  7. [Python Cookbook]Pandas: How to increase columns for DataFrame?Join/Concat

    1. Combine Two Series series1=pd.Series([1,2,3],name='s1') series2=pd.Series([4,5,6],name='s2') df = ...

  8. 3D打印前途光明,它需要怎样的进化?

    在很长一段时间内,笔者都认为3D打印只会存在于科幻场景内,众多的科技大佬在前几年也和我保持相当一致的看法,代工大王郭台铭曾口出狂言:如果3D打印能够普及,我就把"郭"字倒过来写,时 ...

  9. Linux-线程常见函数

    1.线程创建与回收 (1).pthread_create 主线程用来创造子线程 (2).pthread_join 主线程用来等待(阻塞)回收子线程 (3).pthread_detach   主线程用来 ...

  10. runlevel 运行级别

    linux启动过程 关于Ubuntu 12.04修改默认运行级别,启动字符界面的个人理解   网上通常的做法是:(亲自试验,不管用),如果想直接操作请看绿色字体部分 (1)第一种方法:   由于Red ...