Skip to content

Commit

Permalink
feat(root) 新增-starter-freemarker模块
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhengjiaao committed Mar 10, 2022
1 parent 05d7835 commit d001635
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 0 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<module>starter-aop</module>
<module>starter-cache</module>
<module>starter-data</module>
<module>starter-freemarker</module>
<!-- <module>starter-jdbc</module>-->
<module>starter-mail</module>
<!-- <module>starter-oauth2</module>-->
Expand Down
5 changes: 5 additions & 0 deletions starter-freemarker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# starter-freemarker

> FreeMarker Template Language(FTL) 文件一般保存为 xxx.ftl
> - 严格依赖MVC模式,不依赖Servlet容器(不占用JVM内存)
> - 支持内建函数
47 changes: 47 additions & 0 deletions starter-freemarker/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?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/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.zja</groupId>
<artifactId>spring-boot-starter-test-root</artifactId>
<version>2.0-SNAPSHOT</version>
</parent>

<groupId>com.zja</groupId>
<artifactId>starter-freemarker</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.79</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @Company: 上海数慧系统技术有限公司
* @Department: 数据中心
* @Author: 郑家骜[ào]
* @Email: [email protected]
* @Date: 2022-03-10 9:34
* @Since:
*/
package com.zja;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class FreemarkerApplication {

public static void main(String[] args) {
SpringApplication.run(FreemarkerApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @Company: 上海数慧系统技术有限公司
* @Department: 数据中心
* @Author: 郑家骜[ào]
* @Email: [email protected]
* @Date: 2022-03-10 9:48
* @Since:
*/
package com.zja.controller;

import com.zja.properties.ServerSetttings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/freemarker")
public class FreemarkerController {

@Autowired
private ServerSetttings serverSetttings;

//http://127.0.0.1:8080/freemarker/hello
@GetMapping("hello")
public String queryById() {
return "ftl/index";
}

//http://127.0.0.1:8080/freemarker/hello/v2
@RequestMapping("hello/v2")
public String hello(Model model) {
model.addAttribute("server", serverSetttings);
return "ftl/index";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @Company: 上海数慧系统技术有限公司
* @Department: 数据中心
* @Author: 郑家骜[ào]
* @Email: [email protected]
* @Date: 2022-03-10 10:19
* @Since:
*/
package com.zja.properties;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

@Data //lombok插件
@Component
@PropertySource("classpath:resource.properties")
@ConfigurationProperties(prefix = "server")
public class ServerSetttings {
//服务器名称
private String name;
//接口域名
private String domain;
}
12 changes: 12 additions & 0 deletions starter-freemarker/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
spring:
freemarker:
cache: false # 默 false 是否开启thymeleaf缓存,本地开发为false,生产建议为true
charset: UTF-8 # 默 UTF-8
allow-request-override: false # 默 false 允许请求覆盖
check-template-location: true # 默 true 检查模板位置
content-type: text/html # 默 text/html 模板类型
expose-request-attributes: true # 默 false 公开请求属性
expose-session-attributes: true # 默 false 公开会话属性
suffix: .ftlh # 默 .ftlh 模板后缀,boot2.x以后默.ftlh,为了安全问题
template-loader-path: classpath:/templates/ # 默 classpath:/templates/ 模板存放位置

2 changes: 2 additions & 0 deletions starter-freemarker/src/main/resources/resource.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
server.name=spirngboot
server.domain=localhost:8080
12 changes: 12 additions & 0 deletions starter-freemarker/src/main/resources/templates/ftl/index.ftlh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
hello freemarker
server.name:${server.name}
server.domain:${server.domain}
</body>
</html>

0 comments on commit d001635

Please sign in to comment.