要使用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
*/