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. pytorch 自动求梯度

    自动求梯度 在深度学习中,我们经常需要对函数求梯度(gradient).PyTorch提供的autograd包能够根据输入和前向传播过程自动构建计算图,并执行反向传播.本节将介绍如何使用autogra ...

  2. ES6 之 对象的扩展

    1.Object.is() 判断俩个值是否相等 +0 不等于 -0 NaN 等于自身 console.log(Object.is('foo','foo')); // true console.log( ...

  3. Bugku杂项(1—28)

    1.签到题 只要关注公众号就可以得到 flag---开胃菜 2.这是一张单纯的图片 用Winhex打开,会发现最下面有一行编码: key{you are right} 是一串HTML编码,解密下就行了 ...

  4. Dynamics CRM - 如何通过 C# Plugin 给 Contact的 主键(FullName)赋值

    Contact 是 CRM 默认带有的 Entity,主键是 <FullName>,根据开发需求,与主键相关的字段都被设置成隐藏,包括了<Full Name>,<Firs ...

  5. Springboot数据校验

    SpringBoot中使用了Hibernate-validate校验框架 1.在实体类中添加校验规则 校验规则: @NotBlank: 判断字符串是否为null或者是空串(去掉首尾空格).@NotEm ...

  6. Django的模板变量

    变量的值来自context中的数据字典, 类似于字典对象的keys到values的映射关系. 变量是被}}和{{括起来的部分 变量看起来就像是这样: {{ variable }}. 当模版引擎遇到一个 ...

  7. python中的API学习

    URL: url是统一资源定位符,对可以从互联网上得到的资源的位置和访问方法的一种简洁的表示,是互联网上标准资源的地址.互联网上的每个文件都有一个唯一的URL,它包含的信息指出文件的位置以及浏览器应该 ...

  8. python爬虫--cookie反爬处理

    Cookies的处理 作用 保存客户端的相关状态 在爬虫中如果遇到了cookie的反爬如何处理? 手动处理 在抓包工具中捕获cookie,将其封装在headers中 应用场景:cookie没有有效时长 ...

  9. linux虚拟机安装oracle全过程(一)

    起源:为方便系统迁移,导致的不必要的重装软件.故在虚拟机中搭建oracle数据库以及weblogic服务器(所有使用软件及资源链接附在结尾处) 1.安装虚拟机: 1.1.安装vmware 11破解版. ...

  10. PAT Advanced 1092 To Buy or Not to Buy (20) [Hash散列]

    题目 Eva would like to make a string of beads with her favorite colors so she went to a small shop to ...