-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zhengjiaao
committed
Mar 10, 2022
1 parent
05d7835
commit d001635
Showing
9 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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内存) | ||
> - 支持内建函数 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
21 changes: 21 additions & 0 deletions
21
starter-freemarker/src/main/java/com/zja/FreemarkerApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
starter-freemarker/src/main/java/com/zja/controller/FreemarkerController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
starter-freemarker/src/main/java/com/zja/properties/ServerSetttings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ 模板存放位置 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
starter-freemarker/src/main/resources/templates/ftl/index.ftlh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |