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. MySQL笔记 01

    STRUCTURE QUERY LANGUAGE 数据库CRUD操作 DDL: 数据库定义语言,定义数据库数据表结构 CREATE(创建): 创建数据库 CREATE DATABASE 数据库名字; ...

  2. JS的BOM对象

    BOM对象 (一)简介:BOM对象,即浏览器对象模型: 通过javascript的对象,操作和浏览器相关的操作 B:  Browser,浏览器 O: Object,对象 M: Model,模型 (1) ...

  3. 初识MyBatis-Generator

    详细请见: http://www.mybatis.org/generator/quickstart.html 使用mybatis-generator-core-x.x.x.jar加上配置文件来生成 1 ...

  4. promise 核心 几个小问题

    1.如何改变pending的壮体 抛出异常.pending变为rejected  // throw new Error('fail')  内部抛出异常也这样 reason为抛出的error resol ...

  5. ADC分辨率

    转载:http://www.rationmcu.com/elecjc/1874.html 今天给大家简单介绍一下ADC器件的常识. ADC,模数转换器,功能是把模拟电压转换成数字量. 概念听的模糊,说 ...

  6. python 发送邮件,并且带附件

    #!/usr/bin/pythonfrom email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultiparti ...

  7. Exchange 2016 CU12安装报错

    1.         报错信息: Exchange 2016 升级 CU12补丁报错,主要是在进行第10步安装管理工具时报SeSecurityPrivilega错误,详细如下: 查看安装log信息如下 ...

  8. 干货 | 京东云Kubernetes集群+Traefik实战

    摘要 Traefik支持丰富的annotations配置,可配置众多出色的特性,例如:自动熔断.负载均衡策略.黑名单.白名单.所以Traefik对于微服务来说简直就是一神器. 利用Traefik,并结 ...

  9. ZJNU 2356 - 六学家

    “选出来三个六学家,他们的编号是i,j,k,满足i<j<k,且a[k]=a[j]-a[i]” 所以输入第i个数a[i]时,直接让答案加上前i-1个数中能构成差值为a[i]的数量即可 然后让 ...

  10. idea代理上网

    idea 代理上网 浏览器能够上网,idea无法下载jar 浏览器无法上网则配置浏览器代理 --------- start //------------------------浏览器代理完毕 idea ...