SpringBoot整合模板引擎过程代码实例
一、SpringBoot整合freemarker:
1.引入freemarker模板依赖:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> <version>1.5.9.RELEASE</version> </dependency>
2.配置application.properties:
#freemarker 静态资源配置 #设定ftl文件路径 spring.freemarker.template-loader-path=classpath:/templates #关闭缓存,还是刷新,上线生产环境需要改为true spring.freemarker.cache=false spring.freemarker.charset=utf-8 spring.freemarker.check-template-location=true spring.freemarker.content-type=text/html spring.freemarker.expose-request-attributes=true spring.freemarker.expose-session-attributes=true spring.freemarker.request-context-attribute=request spring.freemarker.suffix=.ftl
3.在resources目录下建个目录叫templates,在这个目录下新建一个以.ftl结尾的文件,并且将html代码复制进去,在controller层返回这个视图
二、SpringBoot整合thymeleaf
1.引入thymeleaf模板依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> <version>1.5.9.RELEASE</version> </dependency>
2.配置application.properties:
#thymeleaf静态资源配置 spring.thymeleaf.prefix=classpath:/templates/ spring.thymeleaf.suffix=.html spring.thymeleaf.mode=HTML5 spring.thymeleaf.encoding=UTF-8 spring.thymeleaf.content-type=text/html #关闭缓存,即时刷新,上线生产环境需要改为true spring.thymeleaf.cache=true
3.在resoureces下新建个目录templates在里面编写html文件,具体的thymeleaf标签语法这里就不做介绍了。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
相关推荐
-
Springboot整合thymleaf模板引擎过程解析
这篇文章主要介绍了Springboot整合thymleaf模板引擎过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 thymeleaf作为springboot官方推荐使用的模板引擎,简单易上手,功能强大,thymeleaf的功能和jsp有许多相似之处,两者都属于服务器端渲染技术,但thymeleaf比jsp的功能更强大. 1. thymeleaf入门 1.1 引入坐标 <!--springBoot整合thymeleaf--> <d
-
Spring Boot与Kotlin 整合全文搜索引擎Elasticsearch的示例代码
Elasticsearch 在全文搜索里面基本是无敌的,在大数据里面也很有建树,完全可以当nosql(本来也是nosql)使用. 这篇文章简单介绍Spring Boot使用Kotlin语言连接操作 Elasticsearch.但是不会做很详细的介绍,如果要深入了解Elasticsearch在Java/kotlin中的使用,请参考我之前编写的<Elasticsearch Java API 手册> https://gitee.com/quanke/elasticsearch-java/ 里面包含使
-
SpringBoot整合SpringTask实现定时任务
半藏商城中会有一些用户提交了订单但是一直没有支付的情况,之前我是通过quartz定时任务每天的5点扫描未支付订单然后读取用户的邮箱地址发送邮件提醒用户尽快支付.这次我是采用Spring中自带的SpringTask来进行定时任务. Cron表达式 Cron表达式是一个字符串,包括6~7个时间元素,在SpringTask中可以用于指定任务的执行时间. Cron的语法格式 Seconds Minutes Hours DayofMonth Month DayofWeek Cron格式中每个时间元素的说明
-
Spring Boot整合Elasticsearch实现全文搜索引擎案例解析
简单说,ElasticSearch(简称 ES)是搜索引擎,是结构化数据的分布式搜索引擎.Elastic Search是一个开源的,分布式,实时搜索和分析引擎.Spring Boot为Elasticsearch及Spring Data Elasticsearch提供的基于它的抽象提供了基本的配置.Spring Boot提供了一个用于聚集依赖的spring-boot-starter-data-elasticsearch 'StarterPOM'. 引入spring-boot-starter-dat
-
SpringBoot2整合Drools规则引擎及案例详解
一.Drools引擎简介 1.基础简介 Drools是一个基于java的规则引擎,开源的,可以将复杂多变的规则从硬编码中解放出来,以规则脚本的形式存放在文件中,使得规则的变更不需要修正代码重启机器就可以立即在线上环境生效.具有易于访问企业策略.易于调整以及易于管理的特点,作为开源业务规则引擎,符合业内标准,速度快.效率高. 2.规则语法 (1).演示drl文件格式 package droolRule ; import org.slf4j.Logger import org.slf4j.Logge
-
SpringBoot整合SSO(single sign on)单点登录
1.单点登录三种常见的方式 (1)Session广播机制(Session复制) (2)使用Cookie+Redis实现 (3)使用token实现 2.单点登录介绍 举例: (1)引入jwt依赖 <!-- JWT--> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt</artifactId> </dependency> (2)创建JWTUtil
-
Spring Boot+Drools规则引擎整合详解
目的 官方的Drools范例大都是基于纯Java项目或Maven项目,而基于Spring Boot项目的很少. 本文介绍如何在Spring Boot项目上加上Drools规则引擎. POM依赖 POM文件如下: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=&q
-
SpringBoot整合模板引擎过程代码实例
一.SpringBoot整合freemarker: 1.引入freemarker模板依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> <version>1.5.9.RELEASE</version> </dependency> 2
-
Springboot自动装配实现过程代码实例
创建一个简单的项目: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/PO
-
Springboot使用cache缓存过程代码实例
1.pom.xml <!-- Ehcache 坐标 --> <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache</artifactId> </dependency> 2.ehcache.xml <?xml version="1.0" encoding="UTF-8"?> <ehcach
-
springboot集成fastDfs过程代码实例
这篇文章主要介绍了springboot集成fastDfs过程代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 pom.xml 引入依赖 <dependency> <groupId>com.github.tobato</groupId> <artifactId>fastdfs-client</artifactId> <version>1.26.1-RELEASE</vers
-
Springboot整合通用mapper过程解析
这篇文章主要介绍了springboot整合通用mapper过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 找到springboot工程下的pom.xml文件,导入如下的依赖jar包 <!--配置通用Mapper start--> <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper-spring-boot-starte
-
SpringBoot整合Druid数据源过程详解
这篇文章主要介绍了SpringBoot整合Druid数据源过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 1.数据库结构 2.项目结构 3.pom.xml文件 <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</ar
-
SpringBoot整合Dubbo zookeeper过程解析
这篇文章主要介绍了SpringBoot整合Dubbo zookeeper过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 docker pull zookeeper docker run --name zk01 -p 2181:2181 --restart always -d 2e30cac00aca 表明zookeeper已成功启动 Zookeeper和Dubbo• ZooKeeperZooKeeper 是一个分布式的,开放源码的分布式
-
Springboot整合GuavaCache缓存过程解析
这篇文章主要介绍了springboot整合GuavaCache缓存过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 Guava Cache是一种本地缓存机制,之所以叫本地缓存,是因为它不会把缓存数据放到外部文件或者其他服务器上,而是存放到了应用内存中. Guava Cache的优点是:简单.强大.轻量级. GuavaCache适用场景: 1.某些接口或者键值会被查询多次以上: 2.愿意使用或牺牲一些内存空间来提升访问或者计算速度: 3.缓
-
解析SpringBoot整合SpringDataRedis的过程
Spring-Data-Redis项目(简称SDR)对Redis的Key-Value数据存储操作提供了更高层次的抽象,类似于Spring Framework对JDBC支持一样. 项目主页: http://projects.spring.io/spring-data-redis/ 项目文档: http://docs.spring.io/spring-data/redis/docs/1.5.0.RELEASE/reference/html/ 本文给大家介绍SpringBoot整合SpringData
随机推荐
- EF 配置Oracle数据库数据库连接字符串的实例
- 如何获知并显示文件的大小?
- EasyUI实现二级页面的内容勾选的方法
- Node.js 中exports 和 module.exports 的区别
- win2k3SP2,VS2005SP1,SQL2005SP2整合方法分析小结第1/3页
- 解决Oracle批量修改问题
- javascript一元操作符(递增、递减)使用示例
- 容易造成JavaScript内存泄露几个方面
- unity3d调用手机或电脑摄像头
- PHP生成随机字符串(3种方法)
- Python random模块(获取随机数)常用方法和使用例子
- Android中RecyclerView嵌套滑动冲突解决的代码片段
- 数组与List之间相互转换的方法详解
- Maven模版Bug及解决办法
- c#给图片添加文字的代码小结
- 谈一谈autofac组件的实例范围
- vuex中的 mapState,mapGetters,mapActions,mapMutations 的使用
- Node.js成为Web应用开发最佳选择的原因
- Android 弹出Dialog时隐藏状态栏和底部导航栏的方法
- 微信小程序与公众号卡券/会员打通的问题