From e8eefe57031a18cf961d3753552b084adc4f0421 Mon Sep 17 00:00:00 2001
From: bunny <1319900154@qq.com>
Date: Wed, 22 May 2024 14:13:33 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 1 +
service/pom.xml | 5 +
service/src/main/resources/html/demo1.html | 10 ++
service/src/main/resources/tools.xml | 6 +
.../resources/vms/java/TemplateController.vm | 24 ++++
.../src/main/resources/vms/java/demo 01.vm | 10 ++
.../bunny/service/test/TestVelocityTools.java | 41 ++++++
velocity-tools/pom.xml | 126 ++++++++++++++++++
.../src/main/resources/html/demo1.html | 13 ++
velocity-tools/src/main/resources/tools.xml | 12 ++
.../src/main/resources/vms/demo 01.vm | 15 +++
.../src/main/resources/vms/demo 02.vm | 13 ++
.../src/main/resources/vms/demo 03.vm | 13 ++
.../src/test/java/cn/bunny/TestVelocity.java | 99 ++++++++++++++
14 files changed, 388 insertions(+)
create mode 100644 service/src/main/resources/html/demo1.html
create mode 100644 service/src/main/resources/tools.xml
create mode 100644 service/src/main/resources/vms/java/TemplateController.vm
create mode 100644 service/src/main/resources/vms/java/demo 01.vm
create mode 100644 service/src/test/java/cn/bunny/service/test/TestVelocityTools.java
create mode 100644 velocity-tools/pom.xml
create mode 100644 velocity-tools/src/main/resources/html/demo1.html
create mode 100644 velocity-tools/src/main/resources/tools.xml
create mode 100644 velocity-tools/src/main/resources/vms/demo 01.vm
create mode 100644 velocity-tools/src/main/resources/vms/demo 02.vm
create mode 100644 velocity-tools/src/main/resources/vms/demo 03.vm
create mode 100644 velocity-tools/src/test/java/cn/bunny/TestVelocity.java
diff --git a/pom.xml b/pom.xml
index 0f2db69..11f329f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,6 +20,7 @@
model
service
module
+ velocity-tools
diff --git a/service/pom.xml b/service/pom.xml
index c41c1ae..634dd1c 100644
--- a/service/pom.xml
+++ b/service/pom.xml
@@ -40,6 +40,11 @@
org.apache.velocity
velocity-engine-core
+
+ org.apache.velocity.tools
+ velocity-tools-generic
+ 3.1
+
junit
diff --git a/service/src/main/resources/html/demo1.html b/service/src/main/resources/html/demo1.html
new file mode 100644
index 0000000..3bb8e11
--- /dev/null
+++ b/service/src/main/resources/html/demo1.html
@@ -0,0 +1,10 @@
+
+
+
+
+ Title
+
+
+2024-05-22
+
+
\ No newline at end of file
diff --git a/service/src/main/resources/tools.xml b/service/src/main/resources/tools.xml
new file mode 100644
index 0000000..80d645f
--- /dev/null
+++ b/service/src/main/resources/tools.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/service/src/main/resources/vms/java/TemplateController.vm b/service/src/main/resources/vms/java/TemplateController.vm
new file mode 100644
index 0000000..b330338
--- /dev/null
+++ b/service/src/main/resources/vms/java/TemplateController.vm
@@ -0,0 +1,24 @@
+package ${package};
+
+
+@Tag(name = "${tag}")
+@RestController
+@RequestMapping("${requestMapping}")
+public class ${classname}Controller {
+ @Autowired
+ private ${classname}Service ${${classname.toLowerCase()}Service;
+
+ @Operation(summary = "登录接口", description = "后台用户登录接口")
+ @PostMapping("get")
+ public Result get() {
+ LoginVo vo = userService.login(loginDto);
+ return Result.success(vo);
+ }
+
+ @Operation(summary = "发送邮箱验证码", description = "发送邮箱验证码")
+ @PostMapping("list")
+ public Result sendEmail() {
+ userService.sendEmail(email);
+ return Result.success();
+ }
+}
diff --git a/service/src/main/resources/vms/java/demo 01.vm b/service/src/main/resources/vms/java/demo 01.vm
new file mode 100644
index 0000000..7207d3b
--- /dev/null
+++ b/service/src/main/resources/vms/java/demo 01.vm
@@ -0,0 +1,10 @@
+
+
+
+
+ Title
+
+
+${date.get("yyyy-MM-dd")}
+
+
\ No newline at end of file
diff --git a/service/src/test/java/cn/bunny/service/test/TestVelocityTools.java b/service/src/test/java/cn/bunny/service/test/TestVelocityTools.java
new file mode 100644
index 0000000..64dc2e4
--- /dev/null
+++ b/service/src/test/java/cn/bunny/service/test/TestVelocityTools.java
@@ -0,0 +1,41 @@
+package cn.bunny.service.test;
+
+import org.apache.velocity.Template;
+import org.apache.velocity.app.Velocity;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.context.Context;
+import org.apache.velocity.tools.ToolManager;
+import org.junit.jupiter.api.Test;
+
+import java.io.FileWriter;
+import java.util.Date;
+
+public class TestVelocityTools {
+ @Test
+ void testVelocity() throws Exception {
+ // 创建引擎
+ VelocityEngine ve = new VelocityEngine();
+ // 设置模板加载路径,这里设置的是class下
+ ve.setProperty(Velocity.RESOURCE_LOADER, "class");
+ ve.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
+ // 进行初始化操作
+ ve.init();
+
+ // 加载toolbox
+ ToolManager manager = new ToolManager();
+ manager.configure("tools.xml");
+
+ // 加载模板,设定模板编码
+ Template tpl = ve.getTemplate("vms/java/demo 01.vm", "UTF-8");
+
+ // 设置初始化数据
+ Context context = manager.createContext();
+ context.put("now", new Date());
+
+ FileWriter fw = new FileWriter("D:\\MyFolder\\velocity-demo\\service\\src\\main\\resources\\html\\demo1.html");
+ // 合并数据到模板
+ tpl.merge(context, fw);
+ // 释放资源
+ fw.close();
+ }
+}
diff --git a/velocity-tools/pom.xml b/velocity-tools/pom.xml
new file mode 100644
index 0000000..593a4cd
--- /dev/null
+++ b/velocity-tools/pom.xml
@@ -0,0 +1,126 @@
+
+ 4.0.0
+
+ cn.bunny
+ velocity-demo
+ 0.0.1-SNAPSHOT
+
+
+ velocity-tools
+ jar
+
+ velocity-tools
+ https://maven.apache.org
+
+
+ UTF-8
+ 192.168.3.98:1100
+ 192.168.3.98:2375
+ bunny-service
+
+
+
+
+ cn.bunny
+ module-mail
+ 0.0.1-SNAPSHOT
+
+
+ cn.bunny
+ module-minio
+ 0.0.1-SNAPSHOT
+
+
+
+ org.apache.velocity
+ velocity-engine-core
+
+
+ org.apache.velocity.tools
+ velocity-tools-generic
+ 3.1
+
+
+
+ junit
+ junit
+ 3.8.1
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+
+
+
+ org.springframework.boot
+ spring-boot-starter-websocket
+
+
+
+ org.aspectj
+ aspectjrt
+
+
+ org.aspectj
+ aspectjweaver
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ 21
+ 21
+ utf-8
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ true
+
+
+
+ com.spotify
+ docker-maven-plugin
+ 1.2.2
+
+
+
+ build-image
+
+ package
+
+ build
+ push
+
+
+
+
+ harbor
+ http://${docker.repostory}
+
+ http://${docker.host}
+
+
+ ${docker.repostory}/${docker.registry.name}/${project.artifactId}:${project.version}
+
+
+ ${project.basedir}
+
+ false
+
+
+
+
+
diff --git a/velocity-tools/src/main/resources/html/demo1.html b/velocity-tools/src/main/resources/html/demo1.html
new file mode 100644
index 0000000..2d95e33
--- /dev/null
+++ b/velocity-tools/src/main/resources/html/demo1.html
@@ -0,0 +1,13 @@
+
+
+
+
+ Title
+
+
+查看地址 : https://velocity.apache.org/tools/3.0/tools-summary.html#MathTool
+ 521.76
+ 5558.374400000001
+ -500.0
+
+
\ No newline at end of file
diff --git a/velocity-tools/src/main/resources/tools.xml b/velocity-tools/src/main/resources/tools.xml
new file mode 100644
index 0000000..a112c68
--- /dev/null
+++ b/velocity-tools/src/main/resources/tools.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/velocity-tools/src/main/resources/vms/demo 01.vm b/velocity-tools/src/main/resources/vms/demo 01.vm
new file mode 100644
index 0000000..73bae9a
--- /dev/null
+++ b/velocity-tools/src/main/resources/vms/demo 01.vm
@@ -0,0 +1,15 @@
+
+
+
+
+ Title
+
+
+ ${date.get("yyyy-MM-dd hh:mm:ss")}
+ $date.getYear()
+
+格式化时间
+ $date.format($now)
+ $date.format("yyyy.mm.ss hh:mm:ss",$now)
+
+
\ No newline at end of file
diff --git a/velocity-tools/src/main/resources/vms/demo 02.vm b/velocity-tools/src/main/resources/vms/demo 02.vm
new file mode 100644
index 0000000..2054b7f
--- /dev/null
+++ b/velocity-tools/src/main/resources/vms/demo 02.vm
@@ -0,0 +1,13 @@
+
+
+
+
+ Title
+
+
+原始数据:$num
+格式化数据:$number.format($num)
+取整:$number.integer($num)
+将字符串转为number:$number.toNumber($str)
+
+
\ No newline at end of file
diff --git a/velocity-tools/src/main/resources/vms/demo 03.vm b/velocity-tools/src/main/resources/vms/demo 03.vm
new file mode 100644
index 0000000..5e032d1
--- /dev/null
+++ b/velocity-tools/src/main/resources/vms/demo 03.vm
@@ -0,0 +1,13 @@
+
+
+
+
+ Title
+
+
+查看地址 : https://velocity.apache.org/tools/3.0/tools-summary.html#MathTool
+ $math.add($num1,$num2)
+ $math.mul($num1,$num2)
+ $math.sub($num1,$num2)
+
+
\ No newline at end of file
diff --git a/velocity-tools/src/test/java/cn/bunny/TestVelocity.java b/velocity-tools/src/test/java/cn/bunny/TestVelocity.java
new file mode 100644
index 0000000..390ec9d
--- /dev/null
+++ b/velocity-tools/src/test/java/cn/bunny/TestVelocity.java
@@ -0,0 +1,99 @@
+package cn.bunny;
+
+import org.apache.velocity.Template;
+import org.apache.velocity.app.Velocity;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.context.Context;
+import org.apache.velocity.tools.ToolManager;
+import org.junit.jupiter.api.Test;
+
+import java.io.FileWriter;
+import java.util.Date;
+
+public class TestVelocity {
+ @Test
+ void testVelocity1() throws Exception {
+ // 创建引擎
+ VelocityEngine ve = new VelocityEngine();
+ // 设置模板加载路径,这里设置的是class下
+ ve.setProperty(Velocity.RESOURCE_LOADER, "class");
+ ve.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
+ // 进行初始化操作
+ ve.init();
+
+ // 加载toolbox
+ ToolManager manager = new ToolManager();
+ manager.configure("tools.xml");
+
+ // 加载模板,设定模板编码
+ Template tpl = ve.getTemplate("vms/java/demo 01.vm", "UTF-8");
+
+ // 设置初始化数据
+ Context context = manager.createContext();
+ context.put("now", new Date());
+
+ FileWriter fw = new FileWriter("D:\\MyFolder\\velocity-demo\\velocity-tools\\src\\main\\resources\\html\\demo1.html");
+ // 合并数据到模板
+ tpl.merge(context, fw);
+ // 释放资源
+ fw.close();
+ }
+
+ @Test
+ void testVelocity2() throws Exception {
+ // 创建引擎
+ VelocityEngine ve = new VelocityEngine();
+ // 设置模板加载路径,这里设置的是class下
+ ve.setProperty(Velocity.RESOURCE_LOADER, "class");
+ ve.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
+ // 进行初始化操作
+ ve.init();
+
+ // 加载toolbox
+ ToolManager manager = new ToolManager();
+ manager.configure("tools.xml");
+
+ // 加载模板,设定模板编码
+ Template tpl = ve.getTemplate("vms/demo 02.vm", "UTF-8");
+
+ // 设置初始化数据
+ Context context = manager.createContext();
+ context.put("num", 10.88);
+ context.put("str", "510.88");
+
+ FileWriter fw = new FileWriter("D:\\MyFolder\\velocity-demo\\velocity-tools\\src\\main\\resources\\html\\demo1.html");
+ // 合并数据到模板
+ tpl.merge(context, fw);
+ // 释放资源
+ fw.close();
+ }
+
+ @Test
+ void testVelocity3() throws Exception {
+ // 创建引擎
+ VelocityEngine ve = new VelocityEngine();
+ // 设置模板加载路径,这里设置的是class下
+ ve.setProperty(Velocity.RESOURCE_LOADER, "class");
+ ve.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
+ // 进行初始化操作
+ ve.init();
+
+ // 加载toolbox
+ ToolManager manager = new ToolManager();
+ manager.configure("tools.xml");
+
+ // 加载模板,设定模板编码
+ Template tpl = ve.getTemplate("vms/demo 03.vm", "UTF-8");
+
+ // 设置初始化数据
+ Context context = manager.createContext();
+ context.put("num1", 10.88);
+ context.put("num2", 510.88);
+
+ FileWriter fw = new FileWriter("D:\\MyFolder\\velocity-demo\\velocity-tools\\src\\main\\resources\\html\\demo1.html");
+ // 合并数据到模板
+ tpl.merge(context, fw);
+ // 释放资源
+ fw.close();
+ }
+}