`
san_yun
  • 浏览: 2637750 次
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

springboot 整合freemarker

 
阅读更多

Spring Boot入门——freemarker

 

使用步骤:

1、在pom.xml中添加相关依赖

  <!-- 添加freemarker依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-freemarker</artifactId>
    </dependency>

2、关闭freemarker缓存

 
spring.freemarker.cache=false
spring.freemarker.allow-request-override=false # Set whether HttpServletRequest attributes are allowed to override (hide) controller generated model attributes of the same name.
spring.freemarker.allow-session-override=false # Set whether HttpSession attributes are allowed to override (hide) controller generated model attributes of the same name.
spring.freemarker.cache=false # Enable template caching.
spring.freemarker.charset=UTF-8 # Template encoding.
spring.freemarker.check-template-location=true # Check that the templates location exists.
spring.freemarker.content-type=text/html # Content-Type value.
spring.freemarker.enabled=true # Enable MVC view resolution for this technology.
spring.freemarker.expose-request-attributes=false # Set whether all request attributes should be added to the model prior to merging with the template.
spring.freemarker.expose-session-attributes=false # Set whether all HttpSession attributes should be added to the model prior to merging with the template.
spring.freemarker.expose-spring-macro-helpers=true # Set whether to expose a RequestContext for use by Spring's macro library, under the name "springMacroRequestContext".
spring.freemarker.prefer-file-system-access=true # Prefer file system access for template loading. File system access enables hot detection of template changes.
spring.freemarker.prefix= # Prefix that gets prepended to view names when building a URL.
spring.freemarker.request-context-attribute= # Name of the RequestContext attribute for all views.
spring.freemarker.settings.*= # Well-known FreeMarker keys which will be passed to FreeMarker's Configuration.
spring.freemarker.suffix= # Suffix that gets appended to view names when building a URL.
spring.freemarker.template-loader-path=classpath:/templates/ # Comma-separated list of template paths.
spring.freemarker.view-names= # White list of view names that can be resolved.
 配置
spring.freemarker.template-loader-path=classpath:/templates/
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
spring.freemarker.settings.classic_compatible=true
 

3、编写模板文件.ftl

 

 
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"  
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<meta charset="UTF-8" />
<title>Insert title here</title>
</head>
<body>
    <h1 th:inlines="text">Hello</h1>
    <p th:text="${hello}"></p>
</body>
</html>
 

 

4、编写访问文件的controller

 

 
@Controller
public class FreemarkerController {

    @RequestMapping("index")
    public String indexHtml(Map<String, Object> map){
        map.put("hello", "this is a freemarker test");
        return "/index";
    }  
}
 
 
 
分享到:
评论

相关推荐

    springboot整合freemarker生成静态html的demo.zip

    在本项目"springboot整合freemarker生成静态html的demo.zip"中,我们将探讨如何将SpringBoot框架与FreeMarker模板引擎结合,以实现动态数据驱动的静态HTML页面生成。FreeMarker是一个强大的、开源的模板语言,它允许...

    Springboot整合freemarker 404问题解决方案

    Springboot整合Freemarker 404问题解决方案 Springboot是一个基于Java的开源框架,Freemarker是一个流行的模板引擎,而在Springboot中整合Freemarker时,可能会遇到404问题,本文将详细介绍解决方案。 Springboot...

    SpringBoot集成Freemarker+FlyingSaucer实现pdf在线预览.pdf

    SpringBoot集成Freemarker+FlyingSaucer实现pdf在线预览 本文讲述如何使用SpringBoot集成Freemarker和FlyingSaucer实现PDF在线预览、打印和下载的功能。该技术方案可以应用于各种在线文档预览、报表生成、电子邮件...

    springboot整合FreeMarker模板,完成页面静态化处理

    springboot整合FreeMarker模板,完成页面静态化处理

    SpringBoot整合freemarker的讲解

    SpringBoot整合FreeMarker的讲解 在本篇文章中,我们将详细介绍如何将FreeMarker模板引擎整合到SpringBoot项目中。FreeMarker是一个流行的模板引擎,能够将数据渲染到客户端,提高页面的渲染效率。 首先,需要在...

    springboot整合freemarker详解

    SpringBoot整合FreeMarker详解 SpringBoot是一个基于Java的开源框架,旨在简化企业级应用程序的开发,而FreeMarker是一个基于模板引擎,用于生成静态HTML页面。今天,我们将探讨如何将FreeMarker与SpringBoot整合...

    springboot整合freemarker例子

    在Spring Boot框架中,整合Freemarker是一个常见的需求,它允许开发者使用模板引擎来动态生成HTML页面。Freemarker是一个强大的、轻量级的、基于模板的语言,它与Java紧密集成,广泛应用于Web开发中。下面我们将深入...

    springboot中使用freemarker动态生成word文档,以及使用POI导出自定义格式Excel

    Springboot项目中: 1. 使用Apache POI 3.9 自定义样式导出Excel文件; 2. 使用freemarker动态生成word .doc文档(带图片Word以及复杂格式word) 详细说明见个人博客及 github: ...

    SpringBoot整合Freemarker.docx

    ### Spring Boot 整合 Freemarker 的详细步骤及原理 #### 一、概述 Spring Boot 是一个简化 Spring 应用程序开发的框架,它利用“约定优于配置”的理念,尽可能地减少开发者所需编写的配置量。而 Freemarker 是一...

    基于SpringBoot的Freemarker模板代码生成器.rar

    项目下载后自行修改application-dev.yml和jdbc.properties中的数据库链接。 启动项目后进入http://xxxx.xxxx.xxxx:xxx/swagger-ui.html查看相关接口,支持通过接口设置数据库链接切换后自动重启项目,代码生成器支持...

    springboot集成freemarker和shiro框架

    **五、整合FreeMarker与Shiro** 1. 在FreeMarker模板中使用Shiro标签库:在.ftl文件顶部引入Shiro标签库: ```html ${'@org.apache.shiro.web.tags.ShiroTagLibHandler@getTagLibUri()'}"&gt; ${shiro}" as shiro/&gt; ```...

    SpringBoot使用FreeMarker模板发送邮件

    通过springboot 整合freemarker模板引擎,自动发送html格式邮件

    springboot整合freemarker

    本项目解决了搭建springboot过程中遇到的以下几个问题: 1.不需要tomcat启动web页面 2.修改启动的端口号 3.修改配置文件的目录 4.整合freemarker,并使用layout结构 5.修改项目的目录结构

    springboot 整合 freemarker代码实例

    在Spring Boot应用中整合FreeMarker模板引擎,可以让开发者更加便捷地构建动态HTML页面。下面将详细介绍如何进行这个过程,以及代码实例中的各个部分的作用。 首先,我们需要在`pom.xml`文件中添加必要的依赖。在给...

    springboot-freemarker-master.rar_freemarker_springboot

    本篇文章将详细探讨如何在SpringBoot项目中整合并运用Freemarker,以及相关的配置与使用技巧。 1. **Freemarker简介** Freemarker是一款基于模板的、动态语言,主要用于生成HTML或者其他文本格式的输出。它采用...

    freemarker导出doc及docx

    SpringBoot整合Freemarker** SpringBoot简化了Freemarker的集成。在SpringBoot项目中,只需在`pom.xml`中添加Freemarker依赖,然后在`application.properties`中配置相应的模板路径,即可启用Freemarker模板引擎。...

    SpringBoot中整合freemarker示例代码

    总结来说,Spring Boot整合Freemarker主要包括以下步骤: 1. 添加`spring-boot-starter-freemarker`依赖。 2. 在`templates`目录下创建Freemarker模板文件。 3. 创建Controller,返回模板文件名以触发渲染。 4. 在...

    基于SpringBoot+FreeMarker+MyBatis+ExtJs实现的一个通用后台管理系统.zip

    它与SpringBoot整合后,可以无缝对接数据库操作,提供灵活的数据访问层。在这个系统中,MyBatis作为数据访问层,负责处理SQL语句,与数据库进行交互,实现了数据的增删改查功能。 ExtJs是一个用于构建富客户端Web...

    基于SpringBoot+FreeMarker+MyBatis实现的一个通用后台管理系统

    同时,FreeMarker与SpringBoot的整合则让视图层的构建变得简单,通过FreeMarker模板,可以灵活地渲染后台管理系统的各种页面。 5. 后台管理系统组件 一个通用的后台管理系统通常包括用户管理、角色管理、权限管理...

Global site tag (gtag.js) - Google Analytics