springboot 整合thymeleaf 书笔记
pom.xml依赖添加
- <!--引入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>
- <!--引入thymeleaf-->
yml的配置
- spring:
- thymeleaf:
- cache: true
- check-template: true
- check-template-location: true
- encoding: utf-8
- prefix: classpath:/templates/
- servlet:
- content-type: text/html
- suffix: .html
- spring:
实体类的创建
- @Data
- @AllArgsConstructor
- public class Book {
- private Integer id;
- private String name;
- private String author;
- }
- @Data
controller层
- @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;
- }
- }
- @Controller
html视图
- <!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>
- <!DOCTYPE html>
templates->xxx.html
启动项目(http://localhost:8080/book)
springboot 整合thymeleaf 书笔记的更多相关文章
- SpringBoot 整合 Thymeleaf & 如何使用后台模板快速搭建项目
如果你和我一样,是一名 Java 道路上的编程男孩,其实我不太建议你花时间学 Thymeleaf,当然他的思想还是值得借鉴的.但是他的本质在我看来就是 Jsp 技术的翻版(Jsp 现在用的真的很少很少 ...
- SpringBoot 整合thymeleaf
1.Thymeleaf介绍(官网推荐:https://www.thymeleaf.org/doc/articles/thymeleaf3migration.html) Thymeleaf是跟Veloc ...
- 【Springboot】Springboot整合Thymeleaf模板引擎
Thymeleaf Thymeleaf是跟Velocity.FreeMarker类似的模板引擎,它可以完全替代JSP,相较与其他的模板引擎,它主要有以下几个特点: 1. Thymeleaf在有网络和无 ...
- Springboot整合thymeleaf模板
Thymeleaf是个XML/XHTML/HTML5模板引擎,可以用于Web与非Web应用. Thymeleaf的主要目标在于提供一种可被浏览器正确显示的.格式良好的模板创建方式,因此也可以用作静态建 ...
- 三、SpringBoot整合Thymeleaf视图
目录 3.1 Thymeleaf视图介绍 3.2 创建SpringBoot项目 3.2 配置Thymeleaf 3.3 编写Demo 3.4 小结 3.1 Thymeleaf视图介绍 先看下官网的介绍 ...
- springboot整合thymeleaf+tiles示例
网上关于此框架的配置实在不多,因此想记录下来以防忘记 因为公司框架基于上述(公司采用gradle构建项目,楼主采用的是maven),所以楼主能少走些弯路: 1.创建springboot-maven项目 ...
- SpringBoot:2.SpringBoot整合Thymeleaf模板引擎渲染web视图
在Web开发过程中,Spring Boot可以通过@RestController来返回json数据,那如何渲染Web页面?Spring Boot提供了多种默认渲染html的模板引擎,主要有以下几种: ...
- SpringBoot整合EHcache学习笔记
为了提高系统的运行效率,引入缓存机制,减少数据库访问和磁盘IO.下面说明一下ehcache和SpringBoot整合配置 前言介绍 EhCache 是一个纯Java的进程内缓存框架,具有快速.精干等特 ...
- springboot整合Thymeleaf模板引擎
引入依赖 需要引入Spring Boot的Thymeleaf启动器依赖. <dependency> <groupId>org.springframework.boot</ ...
随机推荐
- tensorflow笔记2(北大网课实战)
1.正则化缓解过拟合 正则化在损失函数中引入模型复杂度指标,利用给w加权值,弱化了训练数据的噪声 一般不会正则化b. 2.matplotlib.pyplot 3.搭建模块化的神经网络八股: 前向传播就 ...
- zabbix监控一个机器上的多个java进程的jvm
一.监控安装部署 1.1 JVM端口配置 (/bqhexin/tomcat/bin/catalina.sh)在安装的tomcat路径,找到catalina.sh文件. vim编辑并添加: catali ...
- react 16 性能提升 总结
1. 减少子组件渲染 当 父组件 state 内的某个值(eg:value) 不变时 子组件菜 render shouldComponentUpdate(nextProps, nextState){ ...
- 从 relu 的多种实现来看 torch.nn 与 torch.nn.functional 的区别与联系
从 relu 的多种实现来看 torch.nn 与 torch.nn.functional 的区别与联系 relu多种实现之间的关系 relu 函数在 pytorch 中总共有 3 次出现: torc ...
- CodeForces - 686D 【树的重心】
传送门:http://codeforces.com/problemset/problem/686/D 题意:给你n个节点,其中1为根, 第二行给你2~n的节点的父亲节点编号. 然后是q个询问,求询问的 ...
- 吴裕雄--天生自然 JAVASCRIPT开发学习: HTML DOM - 改变CSS
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 小程序转义字符去空格
<text ].specInfo}}</text> 在微信小程序开发过程中,有时候会用到常用的一些特殊字符如:‘<’.‘>’.‘&’.‘空格’等,微信小程序同样支 ...
- [Java-基础] 注解
引言 在进行Spring Boot 入门的时候,主程序需要@SpringBootApplication 来标注一个主程序类,说明这是一个Spring Boot应用.这个的作用是什么?去掉的话会报错.如 ...
- Redis5新特性Streams作消息队列
前言 Redis 5 新特性中,Streams 数据结构的引入,可以说它是在本次迭代中最大特性.它使本次 5.x 版本迭代中,Redis 作为消息队列使用时,得到更完善,更强大的原生支持,其中尤为明显 ...
- Eclipse 常见Maven web项目
我是从工作到现在一直用的IDEA,编程软件只要你会技术都没什么区别,只是熟与不熟. 1.下载eclipse软件 百度上搜索eclipse或者到官网https://www.eclipse.org/dow ...