首页
  • 2024.1.1.0
  • 2024.1.1.1
  • 2024.1.2.0
  • 2024.1.3.0
  • Java
  • Linux
  • Deploy
  • Application
关于
友情链接
GitHub (opens new window)

Xiao ku

板砖师傅
首页
  • 2024.1.1.0
  • 2024.1.1.1
  • 2024.1.2.0
  • 2024.1.3.0
  • Java
  • Linux
  • Deploy
  • Application
关于
友情链接
GitHub (opens new window)
  • 版本日志
  • 贡献清单
  • 2024.1.3.0

  • 2024.1.2.0

  • 2024.1.1.1

    • Simple-Starter概述
    • 自动装配模块

      • simple-starter-web
      • simple-starter-redisson
      • simple-starter-s3
      • simple-starter-socket
      • simple-starter-grpc
      • simple-starter-datasource
      • simple-starter-freemarker
        • 简介
        • 引入依赖
        • 配置项
        • 功能
          • 格式化
          • 配置项
          • 自定义Freemarker视图
      • simple-starter-cloud
      • simple-starter-encrypt
      • simple-starter-dict
      • simple-starter-email
      • simple-starter-gateway
      • simple-starter-package
    • 服务类模块

    • 工具类模块

  • 2024.1.1.0

  • OpenSource
  • 2024.1.1.1
  • 自动装配模块
xiaoku
2023-04-04
目录

simple-starter-freemarker

# 简介

用于模板引擎应用,使用配置参数简化 资源路径映射到指定的处理器,将常用的配置项默认封装。

# 引入依赖

    <dependencies>
        <dependency>
            <groupId>cn.iosd</groupId>
            <artifactId>simple-starter-freemarker</artifactId>
            <version>Version</version>
        </dependency>
    </dependencies>
1
2
3
4
5
6
7

# 配置项

Freemarker基础配置项示例:

spring:
  application:
    name: simple-demo-freemarker
  freemarker:
    allow-request-override: false
    cache: true
    charset: UTF-8
    check-template-location: true
    content-type: text/html
    expose-request-attributes: false
    expose-session-attributes: false
    expose-spring-macro-helpers: false
    settings:
      number_format: 0.##
    suffix: .ftl
    template-loader-path: classpath:/templates/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

simple配置:

simple:
  freemarker:
    resourceVoList:
      # resourceHandler:访问的前缀 resourceLocations:真实路径
      - resourceHandler:  /Users/**
        resourceLocations:  file:/Users/
1
2
3
4
5
6

# 功能

# 格式化

类:FreemarkerConfig
默认设置Freemarker模板引擎的格式化选项,使用“#”号作为数字格式的分隔符

# 配置项

类:HttpConverterConfig
从配置文件读取,将指定的资源路径映射到指定的处理器上
访问地址前缀->真实路径
配置文件例:

      - resourceHandler:  /ok/**
        resourceLocations:  classpath:/plugin/ok/
1
2

则页面访问

http://127.0.0.1/ok/xxx.js
1

将获取本工程目录classpath资源下,/plugin/ok/xxx.js文件

# 自定义Freemarker视图

类:MyFreemarkerView CustomFreemarker MyFreemarkerView中添加base路径辅助方法,获取访问地址再返回页面,便于静态资源地址使用
例:

<script src="${base}/xxx/xxx.js"></script>
1
上次更新: 2024/03/25, 02:28:08
simple-starter-datasource
simple-starter-cloud

← simple-starter-datasource simple-starter-cloud→

Copyright © 2019-2024
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式