From d001635b3396e63a0fd29a72c71b0e3538281ffe Mon Sep 17 00:00:00 2001 From: Zhengjiaao Date: Thu, 10 Mar 2022 10:27:08 +0800 Subject: [PATCH] =?UTF-8?q?feat(root)=20=E6=96=B0=E5=A2=9E-starter-freemar?= =?UTF-8?q?ker=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 1 + starter-freemarker/README.md | 5 ++ starter-freemarker/pom.xml | 47 +++++++++++++++++++ .../java/com/zja/FreemarkerApplication.java | 21 +++++++++ .../zja/controller/FreemarkerController.java | 38 +++++++++++++++ .../com/zja/properties/ServerSetttings.java | 25 ++++++++++ .../src/main/resources/application.yaml | 12 +++++ .../src/main/resources/resource.properties | 2 + .../main/resources/templates/ftl/index.ftlh | 12 +++++ 9 files changed, 163 insertions(+) create mode 100644 starter-freemarker/README.md create mode 100644 starter-freemarker/pom.xml create mode 100644 starter-freemarker/src/main/java/com/zja/FreemarkerApplication.java create mode 100644 starter-freemarker/src/main/java/com/zja/controller/FreemarkerController.java create mode 100644 starter-freemarker/src/main/java/com/zja/properties/ServerSetttings.java create mode 100644 starter-freemarker/src/main/resources/application.yaml create mode 100644 starter-freemarker/src/main/resources/resource.properties create mode 100644 starter-freemarker/src/main/resources/templates/ftl/index.ftlh diff --git a/pom.xml b/pom.xml index f63a37a..c8b83d4 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,7 @@ starter-aop starter-cache starter-data + starter-freemarker starter-mail diff --git a/starter-freemarker/README.md b/starter-freemarker/README.md new file mode 100644 index 0000000..d26cac4 --- /dev/null +++ b/starter-freemarker/README.md @@ -0,0 +1,5 @@ +# starter-freemarker + +> FreeMarker Template Language(FTL) 文件一般保存为 xxx.ftl +> - 严格依赖MVC模式,不依赖Servlet容器(不占用JVM内存) +> - 支持内建函数 diff --git a/starter-freemarker/pom.xml b/starter-freemarker/pom.xml new file mode 100644 index 0000000..1e5c7e1 --- /dev/null +++ b/starter-freemarker/pom.xml @@ -0,0 +1,47 @@ + + + 4.0.0 + + com.zja + spring-boot-starter-test-root + 2.0-SNAPSHOT + + + com.zja + starter-freemarker + jar + + + + org.springframework.boot + spring-boot-starter-freemarker + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + io.springfox + springfox-boot-starter + 3.0.0 + + + org.projectlombok + lombok + + + com.alibaba + fastjson + 1.2.79 + compile + + + + diff --git a/starter-freemarker/src/main/java/com/zja/FreemarkerApplication.java b/starter-freemarker/src/main/java/com/zja/FreemarkerApplication.java new file mode 100644 index 0000000..dbca645 --- /dev/null +++ b/starter-freemarker/src/main/java/com/zja/FreemarkerApplication.java @@ -0,0 +1,21 @@ +/** + * @Company: 上海数慧系统技术有限公司 + * @Department: 数据中心 + * @Author: 郑家骜[ào] + * @Email: zhengja@dist.com.cn + * @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); + } + +} diff --git a/starter-freemarker/src/main/java/com/zja/controller/FreemarkerController.java b/starter-freemarker/src/main/java/com/zja/controller/FreemarkerController.java new file mode 100644 index 0000000..e982ae8 --- /dev/null +++ b/starter-freemarker/src/main/java/com/zja/controller/FreemarkerController.java @@ -0,0 +1,38 @@ +/** + * @Company: 上海数慧系统技术有限公司 + * @Department: 数据中心 + * @Author: 郑家骜[ào] + * @Email: zhengja@dist.com.cn + * @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"; + } + +} diff --git a/starter-freemarker/src/main/java/com/zja/properties/ServerSetttings.java b/starter-freemarker/src/main/java/com/zja/properties/ServerSetttings.java new file mode 100644 index 0000000..f2fb854 --- /dev/null +++ b/starter-freemarker/src/main/java/com/zja/properties/ServerSetttings.java @@ -0,0 +1,25 @@ +/** + * @Company: 上海数慧系统技术有限公司 + * @Department: 数据中心 + * @Author: 郑家骜[ào] + * @Email: zhengja@dist.com.cn + * @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; +} diff --git a/starter-freemarker/src/main/resources/application.yaml b/starter-freemarker/src/main/resources/application.yaml new file mode 100644 index 0000000..52c5fce --- /dev/null +++ b/starter-freemarker/src/main/resources/application.yaml @@ -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/ 模板存放位置 + diff --git a/starter-freemarker/src/main/resources/resource.properties b/starter-freemarker/src/main/resources/resource.properties new file mode 100644 index 0000000..30cddba --- /dev/null +++ b/starter-freemarker/src/main/resources/resource.properties @@ -0,0 +1,2 @@ +server.name=spirngboot +server.domain=localhost:8080 diff --git a/starter-freemarker/src/main/resources/templates/ftl/index.ftlh b/starter-freemarker/src/main/resources/templates/ftl/index.ftlh new file mode 100644 index 0000000..91ba7cb --- /dev/null +++ b/starter-freemarker/src/main/resources/templates/ftl/index.ftlh @@ -0,0 +1,12 @@ + + + + + Title + + +hello freemarker +server.name:${server.name} +server.domain:${server.domain} + +