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>
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
实体类的创建
@Data
@AllArgsConstructor
public class Book {
private Integer id;
private String name;
private String author;
}
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;
}
}
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>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</ ...
随机推荐
- Mybatis基本配置(一)
1. Mybatis介绍 MyBatis 是支持普通 SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis 消除了几乎所有的JDBC代码和参数的手工设置以及结果集的检索.MyBatis 使用 ...
- 洛谷 P1018乘积最大
题目描述 今年是国际数学联盟确定的“20002000――世界数学年”,又恰逢我国著名数学家华罗庚先生诞辰9090周年.在华罗庚先生的家乡江苏金坛,组织了一场别开生面的数学智力竞赛的活动,你的一个好朋友 ...
- delphi内嵌汇编
{ 前面知道了一个汇编的赋值指令(MOV), 再了解一个加法指令(ADD), 就可以做个例子了. 譬如: ADD AX,BX; 这相当于 Delphi 中的 AX := AX + BX; 另外提前来个 ...
- 修改maven默认仓库(即repository)的路径
原文链接:https://blog.csdn.net/ideality_hunter/article/details/53006188 简要说明:主要操作为新建仓库路径,在maven的conf目录下修 ...
- 7206VXR系列板卡简介(转)
原文链接:https://www.it610.com/article/3116409.htm作者:hjw2011 ATM板卡介绍 板卡PA-A6-OC3MM,PA-A6-OC3SMI,PA-A6-OC ...
- Linux(CENTOS7) Nginx负载均衡简单配置
负载均衡的作用 1.转发功能 按照一定的算法[权重.轮询],将客户端请求转发到不同应用服务器上,减轻单个服务器压力,提高系统并发量. 2.故障移除 通过心跳检测的方式,判断应用服务器当前是否可以正常工 ...
- 视图家族之mixins视图工具类与generics工具视图类
视图家族之mixins视图工具类与generics工具视图类 一.mixins视图工具类 作用: 提供了几种后端视图(对数据资源进行曾删改查)处理流程的实现,如果需要编写的视图属于这五种,则视图可以通 ...
- centos挂载磁盘
Aliyun实例为例 简单操作: 查看磁盘情况:fdisk -l 对数据盘进行分区,一般类似/dev/vdb这种为数据盘 输入fdisk /dev/vdb 对数据盘进行分区.根据提示,输入 n, p ...
- CSS3-选中的锚链接改变指定样式
1.css样式 主角就是:target <a> 标签的 target 属性规定在何处打开链接文档,连接文档也可以是一个样式. 如果在一个 <a> 标签内包含一个 target ...
- c#连接sql server数据库字符串
第一种方式 Data Source=数据库地址;Initial Catalog=数据库名称;User Id=数据库登录名;Password=数据库密码;[Integrated Security=SSP ...