您的位置:首页 > 教育 > 培训 > 银行外包不是人干的_海南省海洋监测预报中心_icp备案查询官网_推广app平台

银行外包不是人干的_海南省海洋监测预报中心_icp备案查询官网_推广app平台

2025/5/21 23:42:16 来源:https://blog.csdn.net/muriyue6/article/details/142327295  浏览:    关键词:银行外包不是人干的_海南省海洋监测预报中心_icp备案查询官网_推广app平台
银行外包不是人干的_海南省海洋监测预报中心_icp备案查询官网_推广app平台

springboot 项目使用 gitlab 的 API

    • 前言
    • 获取用户 access token
    • Spring boot项目集成GitLab依赖
      • 1 pom依赖
      • 2 配置文件
      • 3 启动类
      • 4 核心代码
    • gitlab 的 API 说明

前言

需求是通过gitlab的api获取其中的数据。

gitlab官方API文档:https://docs.gitlab.com/ee/api/users.html
在这里插入图片描述

gitlab的github地址:https://github.com/eutkin/gitlab4j-api/
在这里插入图片描述

获取用户 access token

首先我们需要获取gitlab的用户 access token, 并且在请求的时候附带这个token,gitlab才能认证我们的身份并返回数据。

1.登录 GitLab。
在这里插入图片描述

2.登录后,点击右上角的头像图标然后选择 Preferences。
在这里插入图片描述
在这里插入图片描述

3.在 access token 界面就可以新建token了。
在这里插入图片描述

当你是group的管理员之后,就可以通过该token获取users了。

Spring boot项目集成GitLab依赖

1 pom依赖

<dependency><groupId>org.gitlab4j</groupId><artifactId>gitlab4j-api</artifactId><version>5.3.0</version>
</dependency>

2 配置文件

server:port: 8899spring:# 配置数据源datasource:url: jdbc:mysql://127.0.0.1:3306/db?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2b8username: rootpassword: rootdriver-class-name: com.mysql.cj.jdbc.Drivertype: com.zaxxer.hikari.HikariDataSourcemvc:pathmatch:matching-strategy: ant_path_matchermybatis-plus:configuration:log-impl: org.apache.ibatis.logging.stdout.StdOutImpl# 扫描通用枚举包type-enums-package: com.mry.code.count.enumsfiles:upload:path: C:/file/ # 文件存储位置code:count:gitlab:url: http://127.0.0.1:8181/authToken: xxxxxxxx

3 启动类

@MapperScan("com.mry.code.count.mapper")
@EnableTransactionManagement // 事务
@SpringBootApplication
public class SpringbootCodeCountServerApplication {public static void main(String[] args) {SpringApplication.run(SpringbootCodeCountServerApplication.class, args);}}

4 核心代码

@Service
@Slf4j
public class CodeCountService {@Value("${code.count.gitlab.url}")private String url;@Value("${code.count.gitlab.authToken}")private String authToken;/*** 多条件分页查询** @param current 当前页* @param size    页面显示的数据条数* @param project* @return*/public ResponseDTO list(Integer current, Integer size, Project project) throws Exception {GitLabApi gitLabAPI = new GitLabApi(url, authToken)

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com