-
新建maven项目
(1)按照格式创建
重点是 java 后面的包名和类名和方法名 ,要与云函数的执行方法对应,云函数后面会讲
(2)pom.xml 重点修改标为绿色(shade不支持高版本,例如3.2,会打包失败)
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>hanshu</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>hanshu Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
(3)代码编写 (示例)
Hello类
package example;
public class Hello {
public String mainHandler(KeyValueClass kv) {
System.out.println("Hello world!天堂");
System.out.println(String.format("key1* = %s", kv.getKey1()));
System.out.println(String.format("key2* = %s", kv.getKey2()));
return String.format("我是大魔王,征服整个世界");
}
}
KeyValueClass类
package example;
public class KeyValueClass {
String key1;
String key2;
public String getKey1() {
return this.key1;
}
public void setKey1(String key1) {
this.key1 = key1;
}
public String getKey2() {
return this.key2;
}
public void setKey2(String key2) {
this.key2 = key2;
}
public KeyValueClass() {
}
}
(4)打包
点击idea左下角Terminal,直接输入 mvn package 静待打包完成
-
构建云函数
-
开通服务
直接搜索云函数,立即开通即可
-
新建云函数
最后点击完成,及创建完成
-
创建触发器,以api触发为例
word地址: https://docs.qq.com/doc/DSHphYXVieVhvd09U