spring boot 学习(二)spring boot 框架整合 thymeleaf
spring boot 框架整合 thymeleaf
spring boot 的官方文档中建议开发者使用模板引擎,避免使用 JSP。因为若一定要使用 JSP 将无法使用。
注意:本文主要参考学习了大神程序员DD的博客。
附上,相应链接:http://blog.didispace.com/springbootweb/
关于 thymeleaf 模板引擎的介绍
thymeleaf 学习笔记
同时,模板引擎默认的模板配置路径为:src/main/resources/templates
。
Spring Boot中使用Thymeleaf
引入依赖,并在默认的模板路径src/main/resources/templates
下编写模板文件。
附上依赖:
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId><version>1.4.3.RELEASE</version>
</dependency>
直接在 Controller 中调用模板即可
@Controller
public class HelloController {@RequestMapping("/")public String index(ModelMap map) {// 加入一个属性,用来在模板中读取map.addAttribute("host", "http://blog.didispace.com");// return模板文件的名称,对应src/main/resources/templates/index.htmlreturn "index"; }
}
<!DOCTYPE html>
<html>
<head lang="en"><meta charset="UTF-8" /><title></title>
</head>
<body>
<h1 th:text="${host}">Hello World</h1>
</body>
</html>
直接打开html页面展现Hello World,但是启动程序后,访问http://localhost:8080/
,则是展示Controller中host的值:http://blog.didispace.com
,做到了不破坏HTML自身内容的数据逻辑分离。
Thymeleaf的默认参数配置
如有需要修改默认配置的时候,只需复制下面要修改的属性到application.properties
中,并修改成需要的值,如修改模板文件的扩展名,修改默认的模板路径等。
# 是否开启模板缓存,默认true
spring.thymeleaf.cache=true
# 检查模板位置是否存在
spring.thymeleaf.check-template-location=true
# Content-Type value
spring.thymeleaf.content-type=text/html
# 是否启用MVC-Thymeleaf视图
spring.thymeleaf.enabled=true
# 模板编码
spring.thymeleaf.encoding=UTF-8
# 应该从解析中排除的视图名称列表(用逗号分隔)
spring.thymeleaf.excluded-view-names=
# 要应用于模板的模板模式。另请参见StandardTemplateModeHandlers。
spring.thymeleaf.mode=HTML5
# 在链接网址时预先查看名称的前缀。
spring.thymeleaf.prefix=classpath:/templates/
# 链接网址时附加到视图名称的后缀。
spring.thymeleaf.suffix=.html
# 指定模板的解析顺序,默认为第一个.
spring.thymeleaf.template-resolver-order=
# 指定使用模板的视图名,多个以逗号分隔
spring.thymeleaf.view-names=
SpringBoot配置属性系列
SpringBoot配置属性
转载于:https://www.cnblogs.com/MaxElephant/p/8108242.html
spring boot 学习(二)spring boot 框架整合 thymeleaf相关推荐
- spring security 学习二
spring security 学习二 doc:https://docs.spring.io/spring-security/site/docs/ 基于表单的认证(个性化认证流程): 一.自定义登录页 ...
- Spring Boot系列二 Spring @Async异步线程池用法总结
转载 自 https://blog.csdn.net/hry2015/article/details/67640534 1. TaskExecutor Spring异步线程池的接口类,其实质是java ...
- (Spring+SpringMVC+MyBatis)SSM三大框架整合教程
目录 一.基本概念 1.Spring 2.SpringMVC 3.MyBatis 二.开发环境搭建 三.Maven Web项目创建 四.SSM整合 1.Maven引入需要的JAR包 2.Spring与 ...
- springmvc+spring+mybatis基于soa架构进行框架整合思路分析
springmvc也可以初始化一个容器,因此不必须在表现层整合spring. service打的是war包,其他关联的工程如interface,pojo,dao等最终的形式会被打为一个jar包,会放到 ...
- Spring 入门学习二之IOC
今天来学习Spring ioc . 一.spring jar 包导入 在 spring 官网下载开发包 spring-framework-4.2.4.RELEASE,然后导入需要的 jar 包到项目 ...
- Spring boot 学习二:入门
1: 需要的环境: JDK:至少JDK7才支持Spring boot maven:至少3.2 spring-boot:1.2.5.RELEASE(在pom.xml中指定) 2: 创建一个maven工程 ...
- 2.SpringBoot学习(二)——Spring Boot ConfigurationProperties
1.简介 1.1 概述 Annotation for externalized configuration. Add this to a class definition or a @Bean met ...
- Spring Boot学习笔记——Spring Boot与ActiveMQ的集成
Spring Boot对JMS(Java Message Service,Java消息服务)也提供了自动配置的支持,其主要支持的JMS实现有ActiveMQ.Artemis等.这里以ActiveMQ为 ...
- Spring Cloud 学习二(Eureka)
1.Eureka Eureka是spring cloud中的服务框架,提供基于rest的服务.它将管理整个系统注册的服务,维护这些服务并检查它们的状态.简单来说就像超市收银台,所有的商品都会在收银台有 ...
最新文章
- Django 和 Ajax 简介
- java-集合排序,队列,散列表map以及如何遍历
- discuz云平台报调用远程接口失败的问题分析和解决
- 测试MVC3时关于Model Builder语句的更改
- UIScrollview 技巧
- 【iOS】UITabView/UICollectionView 全选问题
- 前台传到后台类型数组对象
- ubuntu 安装php 扩展和查看扩展包
- 阶段3 1.Mybatis_08.动态SQL_01.mybatis中的动态sql语句-if标签
- java xppreader_Java對象轉換XML文件:XStream+XPP | 學步園
- bp神经网络的应用案例,bp神经网络数学模型
- 你被选中了——晚会上的随机点名
- html涟漪效果,涟漪效果.html
- 乐山计算机学校学籍管理,乐山计算机学校学生管理系统设计与实现
- uni app中使用图表
- 程序员就是这样聊天把女朋友聊没的。。。
- 计算机系统的组成基础知识,计算机系统的组成基础知识.ppt
- 为何把2点半比作是神奇的2点半? 为什么炒股的人叫14:30分,叫神奇的2点
- BAP:PPP 带宽分配协议 BACP:PPP 带宽分配控制协议--网络大典
- fhq-Treap题目记录