跳到主要内容

快速开始

本章节将帮助您快速开始使用 Jeeapp Spring Boot。

系统要求

Jeeapp Spring Boot 1.2.4-SNAPSHOT 需要以下环境:

Maven 安装

Jeeapp Spring Boot 提供了 BOM (Bill of Materials) 来管理依赖版本。在您的 pom.xml 中添加以下配置:

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.jeeapp.spring.boot</groupId>
<artifactId>jeeapp-spring-boot-dependencies</artifactId>
<version>{project-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

然后添加所需的 Starter 依赖,例如:

<dependencies>
<dependency>
<groupId>com.jeeapp.spring.boot</groupId>
<artifactId>dingtalk-spring-boot-starter</artifactId>
</dependency>
</dependencies>

Gradle 安装

在 Gradle 项目中,您可以这样配置:

dependencies {
implementation platform('com.jeeapp.spring.boot:jeeapp-spring-boot-dependencies:{project-version}')
implementation 'com.jeeapp.spring.boot:dingtalk-spring-boot-starter'
}

创建第一个应用

以下是一个使用钉钉集成的简单示例:

Maven 依赖

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.jeeapp.spring.boot</groupId>
<artifactId>dingtalk-spring-boot-starter</artifactId>
</dependency>

配置文件

application.yml 中添加配置:

dingtalk:
app-type: INTERNAL
client-id: your-app-key
client-secret: your-app-secret
corp-id: your-corp-id
agent-id: your-agent-id

代码示例

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jeeapp.dingtalk.DingTalkTemplate;
import lombok.RequiredArgsConstructor;

@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}

@RestController
@RequiredArgsConstructor
class DingTalkController {

private final DingTalkTemplate dingTalkTemplate;

@GetMapping("/user")
public Object getUser(String userId) throws Exception {
com.aliyun.dingtalkcontact_1_0.Client client = dingTalkTemplate.createClient(com.aliyun.dingtalkcontact_1_0.Client.class);
return client.getUser(userId).getBody();
}
}

运行应用

运行 DemoApplication 类,然后访问 http://localhost:8080/user?userId=xxx 即可获取用户信息。

获取帮助

如果您在使用过程中遇到问题: