springboot docapi集成

要使用apidoc就得先安裝nodejs,安裝nodejs後就可以使用npm安裝apidoc了。自行百度安裝方法!

apidoc.json

{
  "name": "api文檔",
  "version": "1.0.0",
  "title": "接口文檔",
  "url": "",
  "sampleUrl": "http://192.168.1.1:8080/xxx",
  "template": {
    "forceLanguage": "zh-cn"
  },
  "template": {
    "withCompare": true,
    "withGenerator": true
  },
  "template": {
    "jQueryAjaxSetup": {
      "contentType": "application/json"
    }
  }
}

注意:這個文件要放在pom.xml同級目錄下。

pom.xml引入maven插件

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2</version>
                <executions>
                    <execution>
                        <id>exec-npm-run-apidoc</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <!-- 不同電腦位置可能不一樣 -->
                    <executable>C:\Users\Yida\AppData\Roaming\npm\apidoc.cmd</executable>
                            <arguments>
                                <argument>-f</argument>
                                <argument>".*\.java$"</argument>
                                <argument>-i</argument>
                                <argument>${basedir}</argument>
                                <argument>-o</argument>
                                <!-- 生成後存放的地址 -->
                                <argument>${basedir}/src/main/resources/apidoc</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

然後就開擼了

可以寫在方法上,也可以全寫在一起。 大家隨意!

  /**
     * @api {get} /allUser 獲取所有用戶
     * @apiGroup user
     * @apiDescription 獲取所有用戶
     * @apiParam {int} code 這兒是參數介紹
     * @apiParamExample {json} Request-Example:
     * {
     *     code: 123455
     * }
     * @apiSuccess {boolean} data 
     */

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章