mirror of
https://gitee.com/yudaocode/SpringBoot-Labs.git
synced 2026-09-03 05:53:54 +08:00
使用 JApiDocs 生成接口
This commit is contained in:
31
lab-24/lab-24-apidoc-japidocs/pom.xml
Normal file
31
lab-24/lab-24-apidoc-japidocs/pom.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.3.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>lab-24-apidoc-japidocs</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- 实现对 Spring MVC 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 引入 JApiDocs 依赖 -->
|
||||
<dependency>
|
||||
<groupId>io.github.yedaxia</groupId>
|
||||
<artifactId>japidocs</artifactId>
|
||||
<version>1.4.4</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
package cn.iocoder.springboot.lab24;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package cn.iocoder.springboot.lab24;
|
||||
|
||||
import io.github.yedaxia.apidocs.Docs;
|
||||
import io.github.yedaxia.apidocs.DocsConfig;
|
||||
import io.github.yedaxia.apidocs.plugin.markdown.MarkdownDocPlugin;
|
||||
|
||||
public class TestJApiDocs {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 1. 创建生成文档的配置
|
||||
DocsConfig config = new DocsConfig();
|
||||
config.setProjectPath("/Users/yunai/Java/SpringBoot-Labs/lab-24/lab-24-apidoc-japidocs"); // 项目所在目录
|
||||
config.setDocsPath("/Users/yunai/Downloads/"); // 生成 HTML 接口文档的目标目录
|
||||
config.setAutoGenerate(true); // 是否给所有 Controller 生成接口文档
|
||||
config.setProjectName("示例项目"); // 项目名
|
||||
config.setApiVersion("V1.0"); // API 版本号
|
||||
config.addPlugin(new MarkdownDocPlugin()); // 使用 MD 插件,额外生成 MD 格式的接口文档
|
||||
// 2. 执行生成 HTML 接口文档
|
||||
Docs.buildHtmlDocs(config);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package cn.iocoder.springboot.lab24.controller;
|
||||
|
||||
import cn.iocoder.springboot.lab24.vo.UserCreateReqVO;
|
||||
import cn.iocoder.springboot.lab24.vo.UserListReqVO;
|
||||
import cn.iocoder.springboot.lab24.vo.UserRespVO;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户 API
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/user/")
|
||||
public class UserController {
|
||||
|
||||
|
||||
/**
|
||||
* 获得用户列表
|
||||
*
|
||||
* @param listReqVO 列表筛选条件
|
||||
* @return 用户列表
|
||||
*/
|
||||
@GetMapping("list")
|
||||
public List<UserRespVO> list(UserListReqVO listReqVO){
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存用户
|
||||
*
|
||||
* @param createReqVO 创建用户信息
|
||||
* @return 用户编号
|
||||
*/
|
||||
@PostMapping("save")
|
||||
public Integer saveUser(@RequestBody UserCreateReqVO createReqVO){
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定编号的用户
|
||||
*
|
||||
* @param id 用户编号
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("delete")
|
||||
public Boolean deleteUser(@RequestParam Long id){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.iocoder.springboot.lab24.vo;
|
||||
|
||||
/**
|
||||
* 用户创建请求 VO
|
||||
*/
|
||||
public class UserCreateReqVO {
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
private String nickname;
|
||||
/**
|
||||
* 年龄
|
||||
*/
|
||||
private Integer age;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package cn.iocoder.springboot.lab24.vo;
|
||||
|
||||
/**
|
||||
* 用户列表请求 VO
|
||||
*/
|
||||
public class UserListReqVO {
|
||||
|
||||
/**
|
||||
* 昵称,模糊匹配
|
||||
*/
|
||||
private String nickname;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package cn.iocoder.springboot.lab24.vo;
|
||||
|
||||
/**
|
||||
* 用户响应 VO
|
||||
*/
|
||||
public class UserRespVO {
|
||||
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
private String nickname;
|
||||
/**
|
||||
* 年龄
|
||||
*/
|
||||
private Integer age;
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
<modules>
|
||||
<module>lab-24-apidoc-swagger</module>
|
||||
<module>lab-24-apidoc-swagger-knife4j</module>
|
||||
<module>lab-24-apidoc-japidocs</module>
|
||||
</modules>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user