This commit is contained in:
parent
1391d9d6da
commit
e8eefe5703
1
pom.xml
1
pom.xml
|
@ -20,6 +20,7 @@
|
||||||
<module>model</module>
|
<module>model</module>
|
||||||
<module>service</module>
|
<module>service</module>
|
||||||
<module>module</module>
|
<module>module</module>
|
||||||
|
<module>velocity-tools</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|
|
@ -40,6 +40,11 @@
|
||||||
<groupId>org.apache.velocity</groupId>
|
<groupId>org.apache.velocity</groupId>
|
||||||
<artifactId>velocity-engine-core</artifactId>
|
<artifactId>velocity-engine-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.velocity.tools</groupId>
|
||||||
|
<artifactId>velocity-tools-generic</artifactId>
|
||||||
|
<version>3.1</version>
|
||||||
|
</dependency>
|
||||||
<!-- 单元测试 -->
|
<!-- 单元测试 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
2024-05-22
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<tools>
|
||||||
|
<toolbox scope="application">
|
||||||
|
<tool class="org.apache.velocity.tools.generic.DateTool"
|
||||||
|
format="yyyy-MM-dd"/>
|
||||||
|
</toolbox>
|
||||||
|
</tools>
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
${date.get("yyyy-MM-dd")}
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,126 @@
|
||||||
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>cn.bunny</groupId>
|
||||||
|
<artifactId>velocity-demo</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>velocity-tools</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>velocity-tools</name>
|
||||||
|
<url>https://maven.apache.org</url>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<docker.repostory>192.168.3.98:1100</docker.repostory>
|
||||||
|
<docker.host>192.168.3.98:2375</docker.host>
|
||||||
|
<docker.registry.name>bunny-service</docker.registry.name>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.bunny</groupId>
|
||||||
|
<artifactId>module-mail</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.bunny</groupId>
|
||||||
|
<artifactId>module-minio</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- velocity -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.velocity</groupId>
|
||||||
|
<artifactId>velocity-engine-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.velocity.tools</groupId>
|
||||||
|
<artifactId>velocity-tools-generic</artifactId>
|
||||||
|
<version>3.1</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- 单元测试 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- spring-test -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- websocket -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- asp 切面 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.aspectj</groupId>
|
||||||
|
<artifactId>aspectjrt</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.aspectj</groupId>
|
||||||
|
<artifactId>aspectjweaver</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>21</source>
|
||||||
|
<target>21</target>
|
||||||
|
<encoding>utf-8</encoding>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<skip>true</skip>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.spotify</groupId>
|
||||||
|
<artifactId>docker-maven-plugin</artifactId>
|
||||||
|
<version>1.2.2</version>
|
||||||
|
<!--将插件绑定在某个phase执行-->
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>build-image</id>
|
||||||
|
<!--将插件绑定在package这个phase(阶段)上。也就是说,用户只需执行mvn package,就会自动执行mvn docker:build-->
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>build</goal>
|
||||||
|
<goal>push</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<serverId>harbor</serverId>
|
||||||
|
<registryUrl>http://${docker.repostory}</registryUrl>
|
||||||
|
<!-- 配置docker主机地址 -->
|
||||||
|
<dockerHost>http://${docker.host}</dockerHost>
|
||||||
|
<!--指定生成的镜像名-->
|
||||||
|
<imageName>
|
||||||
|
${docker.repostory}/${docker.registry.name}/${project.artifactId}:${project.version}
|
||||||
|
</imageName>
|
||||||
|
<!-- 指定 dockerfile 路径-->
|
||||||
|
<dockerDirectory>${project.basedir}</dockerDirectory>
|
||||||
|
<!-- 是否跳过docker构建 -->
|
||||||
|
<skipDockerBuild>false</skipDockerBuild>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -0,0 +1,13 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
查看地址 : https://velocity.apache.org/tools/3.0/tools-summary.html#MathTool
|
||||||
|
521.76
|
||||||
|
5558.374400000001
|
||||||
|
-500.0
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,12 @@
|
||||||
|
<tools>
|
||||||
|
<toolbox scope="application">
|
||||||
|
<tool class="org.apache.velocity.tools.generic.DateTool"
|
||||||
|
format="yyyy-MM-dd"/>
|
||||||
|
</toolbox>
|
||||||
|
<toolbox scope="application">
|
||||||
|
<tool key="number" class="org.apache.velocity.tools.generic.NumberTool"/>
|
||||||
|
</toolbox>
|
||||||
|
<toolbox scope="application">
|
||||||
|
<tool key="math" class="org.apache.velocity.tools.generic.MathTool"/>
|
||||||
|
</toolbox>
|
||||||
|
</tools>
|
|
@ -0,0 +1,15 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
${date.get("yyyy-MM-dd hh:mm:ss")}
|
||||||
|
$date.getYear()
|
||||||
|
|
||||||
|
格式化时间
|
||||||
|
$date.format($now)
|
||||||
|
$date.format("yyyy.mm.ss hh:mm:ss",$now)
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,13 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
原始数据:$num
|
||||||
|
格式化数据:$number.format($num)
|
||||||
|
取整:$number.integer($num)
|
||||||
|
将字符串转为number:$number.toNumber($str)
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,13 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
查看地址 : https://velocity.apache.org/tools/3.0/tools-summary.html#MathTool
|
||||||
|
$math.add($num1,$num2)
|
||||||
|
$math.mul($num1,$num2)
|
||||||
|
$math.sub($num1,$num2)
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue