SpringBoot (11) JApiDocs builds interface documents

JApiDocs build interface documentation

1. Before the front-end and back-end are separated, the front-end manages static interfaces, html and other static resources, and related operations are rendered by the back-end through the template engine. Easy to operate. 2. After the front-end and back-end are separated, the front-end and back-end personnel cannot communicate in a timely manner to solve the problem. Therefore, it is necessary to deal with by generating interface documents , but for back-end programmers do not want to write interface documents, so there is an interface document generation tool, mainly introduces two document generation tools Swagger, JApiDocs.

JApiDocs is an Api document generation tool that conforms to Java programming habits . Maximize the use of Java's grammatical features, you only need to design the interface carefully, add the necessary comments, JApiDocs will help you export a beautiful Html document, and generate related Java and Object-C related data model codes. From then on, Android With IOS students, you can save a lot of code, and you don't need to work hard to maintain the changes in the interface documents, you only need to maintain your code.

1. Add dependencies

<!--JApiDocs构建接口文档依赖-->
<dependency>
    <groupId>io.github.yedaxia</groupId>
    <artifactId>japidocs</artifactId>
    <version>1.4.4</version>
</dependency>

2. Execute the following method in any main entry

The interface document of the project will be generated under the project directory where it is created

public static void main(String[] args) {
    //在测试类中运行main方法,生成html离线文档,在本地运行项目时可以直接当方法写在springboot的启动类中
    //生成japidocs构建接口文档
    DocsConfig config = new DocsConfig();
    // root project path   setProjectPath是项目根目录,
    config.setProjectPath("D:\\Java\\springboot练习\\pro-springboot\\boot05-springBootDemo"); 
    config.setProjectName("项目名称"); // project name
    config.setApiVersion("V1.0");       // api version
    // api docs target path  setDocsPath是文档的生成目录
    config.setDocsPath("D:\\Java\\springboot练习\\pro-springboot\\boot05-springBootDemo\\apidoc"); 
    config.setAutoGenerate(Boolean.TRUE);  // auto generate
    Docs.buildHtmlDocs(config); // execute to generate
}

Open the folder of the project in the folder, you will find one more folder, this is the generated document

 

 

The interface document is generated through the method annotation, and the front-end personnel can see the parameters and return values ​​of the back-end

 

 

Guess you like

Origin blog.csdn.net/m0_65992672/article/details/130421822