1. pom.xml依赖添加

      1. <!--引入thymeleaf-->
      2. <dependency>
      3. <groupId>org.springframework.boot</groupId>
      4. <artifactId>spring-boot-starter-thymeleaf</artifactId>
      5. </dependency>
      6.  
      7. <!--引入谷歌的guava-->
      8. <dependency>
      9. <groupId>com.google.guava</groupId>
      10. <artifactId>guava</artifactId>
      11. <version>19.0</version>
      12. </dependency>
      13.  
      14. <dependency>
      15. <groupId>org.springframework.boot</groupId>
      16. <artifactId>spring-boot-starter-web</artifactId>
      17. </dependency>
  2. yml的配置  

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

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

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

      1. <!DOCTYPE html>
      2. <html lang="en" xmlns:th="http://www.thymeleaf.org">
      3. <html lang="en">
      4. <head>
      5. <meta charset="UTF-8">
      6. <title>图书列表</title>
      7. </head>
      8. <body>
      9. <table border="1">
      10. <tr>
      11. <td>图书编号</td>
      12. <td>图书名称</td>
      13. <td>图书作者</td>
      14. </tr>
      15. <tr th:each="book:${mybook}">
      16. <td th:text="${book.id}"></td>
      17. <td th:text="${book.name}"></td>
      18. <td th:text="${book.author}"></td>
      19. </tr>
      20. </table>
      21. </body>
      22. </html>
    1. 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. tensorflow笔记2(北大网课实战)

    1.正则化缓解过拟合 正则化在损失函数中引入模型复杂度指标,利用给w加权值,弱化了训练数据的噪声 一般不会正则化b. 2.matplotlib.pyplot 3.搭建模块化的神经网络八股: 前向传播就 ...

  2. zabbix监控一个机器上的多个java进程的jvm

    一.监控安装部署 1.1 JVM端口配置 (/bqhexin/tomcat/bin/catalina.sh)在安装的tomcat路径,找到catalina.sh文件. vim编辑并添加: catali ...

  3. react 16 性能提升 总结

    1. 减少子组件渲染 当 父组件 state 内的某个值(eg:value) 不变时 子组件菜 render shouldComponentUpdate(nextProps, nextState){ ...

  4. 从 relu 的多种实现来看 torch.nn 与 torch.nn.functional 的区别与联系

    从 relu 的多种实现来看 torch.nn 与 torch.nn.functional 的区别与联系 relu多种实现之间的关系 relu 函数在 pytorch 中总共有 3 次出现: torc ...

  5. CodeForces - 686D 【树的重心】

    传送门:http://codeforces.com/problemset/problem/686/D 题意:给你n个节点,其中1为根, 第二行给你2~n的节点的父亲节点编号. 然后是q个询问,求询问的 ...

  6. 吴裕雄--天生自然 JAVASCRIPT开发学习: HTML DOM - 改变CSS

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  7. 小程序转义字符去空格&nbsp;

    <text ].specInfo}}</text> 在微信小程序开发过程中,有时候会用到常用的一些特殊字符如:‘<’.‘>’.‘&’.‘空格’等,微信小程序同样支 ...

  8. [Java-基础] 注解

    引言 在进行Spring Boot 入门的时候,主程序需要@SpringBootApplication 来标注一个主程序类,说明这是一个Spring Boot应用.这个的作用是什么?去掉的话会报错.如 ...

  9. Redis5新特性Streams作消息队列

    前言 Redis 5 新特性中,Streams 数据结构的引入,可以说它是在本次迭代中最大特性.它使本次 5.x 版本迭代中,Redis 作为消息队列使用时,得到更完善,更强大的原生支持,其中尤为明显 ...

  10. Eclipse 常见Maven web项目

    我是从工作到现在一直用的IDEA,编程软件只要你会技术都没什么区别,只是熟与不熟. 1.下载eclipse软件 百度上搜索eclipse或者到官网https://www.eclipse.org/dow ...