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</ ...
随机推荐
- SpringMVC:拦截器
SpringMVC:拦截器 概述 SpringMVC的处理器拦截器类似于Servlet开发中的过滤器Filter,用于对处理器进行预处理和后处理.开发者可以自己定义一些拦截器来实现特定的功能. 过 ...
- POJ 1466:Girls and Boys 二分图的最大点独立集
Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submissions: 11097 Accepted: 4960 D ...
- struct寻址&for反汇编
//for 反汇编 #include<stdio.h> int main() { ; ; ;i<;i++) { s=s+; } s=; ;i>=;i--) { s=s+; } ...
- redis官网下载自动安装脚本
注释:使用方法为 # ./redis.sh version ----version为官网版本号 #!/bin/bashversion=$1serverurl='download. ...
- P(Y=y|x;θ)表示什么意思
https://blog.csdn.net/jh1137921986/article/details/88999539 在机器学习中,特别是学习到关于概率/似然估计方面的内容,经常看到类似P(Y=y| ...
- 吴裕雄--天生自然MySQL学习笔记:MySQL 连接的使用
使用 MySQL 的 JOIN 在两个或多个表中查询数据. 可以在 SELECT, UPDATE 和 DELETE 语句中使用 Mysql 的 JOIN 来联合多表查询. JOIN 按照功能大致分为如 ...
- idea创建远程分支
1.先从远程拉取一个完整的分支,master或dev 2.新建一个分支,new,新建的同时checkout 出来 3.把新建的分支push到远程 4.如果新建完分支后写代码了,需要先把代码提交然后一起 ...
- JavaScript学习总结(八)
这一节结束,我们的JavaScript学习总结系列文章第一阶段就要结束了,今后会适当的补充一些高级的内容,敬请期待. 好了,废话不说进入这一节的学习. 联动框 联动框,实在是太常见了.比如淘宝,我们选 ...
- 1. rabbitmq 安装
1. ubuntu 16 18 安装 https://blog.csdn.net/haeasringnar/article/details/82715823 2. centos 7 https://w ...
- sudo apt-get update数字签名错误解决方法
lzb@lzb:~/projects/curl-master$ sudo apt-get update 命中: http://mirrors.aliyun.com/ubuntu xenial InRe ...