Skip to content

Commit 17a49dd

Browse files
author
YunaiV
committed
使用 JApiDocs 生成接口
1 parent 7770689 commit 17a49dd

File tree

9 files changed

+171
-1
lines changed

9 files changed

+171
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.1.3.RELEASE</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<artifactId>lab-24-apidoc-japidocs</artifactId>
14+
15+
<dependencies>
16+
<!-- 实现对 Spring MVC 的自动化配置 -->
17+
<dependency>
18+
<groupId>org.springframework.boot</groupId>
19+
<artifactId>spring-boot-starter-web</artifactId>
20+
</dependency>
21+
22+
<!-- 引入 JApiDocs 依赖 -->
23+
<dependency>
24+
<groupId>io.github.yedaxia</groupId>
25+
<artifactId>japidocs</artifactId>
26+
<version>1.4.4</version>
27+
</dependency>
28+
29+
</dependencies>
30+
31+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cn.iocoder.springboot.lab24;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Application {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(Application.class, args);
11+
}
12+
13+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cn.iocoder.springboot.lab24;
2+
3+
import io.github.yedaxia.apidocs.Docs;
4+
import io.github.yedaxia.apidocs.DocsConfig;
5+
import io.github.yedaxia.apidocs.plugin.markdown.MarkdownDocPlugin;
6+
7+
public class TestJApiDocs {
8+
9+
public static void main(String[] args) {
10+
// 1. 创建生成文档的配置
11+
DocsConfig config = new DocsConfig();
12+
config.setProjectPath("/Users/yunai/Java/SpringBoot-Labs/lab-24/lab-24-apidoc-japidocs"); // 项目所在目录
13+
config.setDocsPath("/Users/yunai/Downloads/"); // 生成 HTML 接口文档的目标目录
14+
config.setAutoGenerate(true); // 是否给所有 Controller 生成接口文档
15+
config.setProjectName("示例项目"); // 项目名
16+
config.setApiVersion("V1.0"); // API 版本号
17+
config.addPlugin(new MarkdownDocPlugin()); // 使用 MD 插件,额外生成 MD 格式的接口文档
18+
// 2. 执行生成 HTML 接口文档
19+
Docs.buildHtmlDocs(config);
20+
}
21+
22+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package cn.iocoder.springboot.lab24.controller;
2+
3+
import cn.iocoder.springboot.lab24.vo.UserCreateReqVO;
4+
import cn.iocoder.springboot.lab24.vo.UserListReqVO;
5+
import cn.iocoder.springboot.lab24.vo.UserRespVO;
6+
import org.springframework.web.bind.annotation.*;
7+
8+
import java.util.List;
9+
10+
/**
11+
* 用户 API
12+
*/
13+
@RestController
14+
@RequestMapping("/api/user/")
15+
public class UserController {
16+
17+
18+
/**
19+
* 获得用户列表
20+
*
21+
* @param listReqVO 列表筛选条件
22+
* @return 用户列表
23+
*/
24+
@GetMapping("list")
25+
public List<UserRespVO> list(UserListReqVO listReqVO){
26+
return null;
27+
}
28+
29+
/**
30+
* 保存用户
31+
*
32+
* @param createReqVO 创建用户信息
33+
* @return 用户编号
34+
*/
35+
@PostMapping("save")
36+
public Integer saveUser(@RequestBody UserCreateReqVO createReqVO){
37+
return 1;
38+
}
39+
40+
/**
41+
* 删除指定编号的用户
42+
*
43+
* @param id 用户编号
44+
* @return 是否成功
45+
*/
46+
@DeleteMapping("delete")
47+
public Boolean deleteUser(@RequestParam Long id){
48+
return true;
49+
}
50+
51+
52+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package cn.iocoder.springboot.lab24.vo;
2+
3+
/**
4+
* 用户创建请求 VO
5+
*/
6+
public class UserCreateReqVO {
7+
8+
/**
9+
* 昵称
10+
*/
11+
private String nickname;
12+
/**
13+
* 年龄
14+
*/
15+
private Integer age;
16+
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cn.iocoder.springboot.lab24.vo;
2+
3+
/**
4+
* 用户列表请求 VO
5+
*/
6+
public class UserListReqVO {
7+
8+
/**
9+
* 昵称,模糊匹配
10+
*/
11+
private String nickname;
12+
13+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package cn.iocoder.springboot.lab24.vo;
2+
3+
/**
4+
* 用户响应 VO
5+
*/
6+
public class UserRespVO {
7+
8+
/**
9+
* 用户编号
10+
*/
11+
private Integer id;
12+
/**
13+
* 昵称
14+
*/
15+
private String nickname;
16+
/**
17+
* 年龄
18+
*/
19+
private Integer age;
20+
21+
}

lab-24/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<modules>
1515
<module>lab-24-apidoc-swagger</module>
1616
<module>lab-24-apidoc-swagger-knife4j</module>
17+
<module>lab-24-apidoc-japidocs</module>
1718
</modules>
1819

1920

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<!-- <module>lab-21</module>-->
3232
<!-- <module>lab-22</module>-->
3333
<!-- <module>lab-23</module>-->
34-
<!-- <module>lab-24</module>-->
34+
<module>lab-24</module>
3535
<!-- <module>lab-25</module>-->
3636
<!-- <module>lab-26</module>-->
3737
<!-- <module>lab-27</module>-->

0 commit comments

Comments
 (0)