1、设置方法注释
首先每个人都应该拥有写注释的规范,IDEA设置如下:
接口统一规范
/** * * @author mujiutian * @date $DATE$ $TIME$ * @param $params$ */
2、pom依赖添加插件
<plugin> <groupId>com.github.shalousun</groupId> <artifactId>smart-doc-maven-plugin</artifactId> <version>1.1.0</version> <configuration> <!--指定生成文档的使用的配置文件,配置文件放在自己的项目中--> <configFile>./src/main/resources/smart-doc.json</configFile> <!--指定项目名称--> <projectName>测试</projectName> <!--smart-doc实现自动分析依赖树加载第三方依赖的源码,如果一些框架依赖库加载不到导致报错,这时请使用excludes排除掉--> <excludes> <!--格式为:groupId:artifactId;参考如下--> <!--1.0.7版本开始你还可以用正则匹配排除,如:poi.* --> <exclude>com.alibaba:fastjson</exclude> </excludes> <!--自1.0.8版本开始,插件提供includes支持--> <!--smart-doc能自动分析依赖树加载所有依赖源码,原则上会影响文档构建效率,因此你可以使用includes来让插件加载你配置的组件--> <includes> <!--格式为:groupId:artifactId;参考如下--> <include>com.alibaba:fastjson</include> </includes> </configuration> <executions> <execution> <!--如果不需要在执行编译时启动smart-doc,则将phase注释掉--> <phase>compile</phase> <goals> <goal>html</goal> </goals> </execution> </executions> </plugin>
3、resources下配置json文件
smart-doc.json文件
{ "serverUrl": "http://127.0.0.1:8083", "isStrict": false, "allInOne": true, "outPath": "/Users/mac/Desktop", "coverOld": true, "packageFilters": "", "md5EncryptedHtmlName": false, "projectName": "雷达", "skipTransientField": true, "showAuthor":true, "requestFieldToUnderline":false, "responseFieldToUnderline":false, "inlineEnum":true, "recursionLimit":7, "revisionLogs": [ { "version": "1.0", "status": "create", "author": "mujiutian", "remarks": "smart测试使用接口文档" } ], "customResponseFields": [ { "name": "code", "desc": "响应代码", "value": "00000" } ], "rpcApiDependencies":[{ "artifactId":"SpringBoot2-Dubbo-Api", "groupId":"com.demo", "version":"1.0.0" }], "rpcConsumerConfig":"src/main/resources/consumer-example.conf", "apiObjectReplacements": [{ "className": "org.springframework.data.domain.Pageable", "replacementClassName": "com.power.doc.model.PageRequestDto" }], "apiConstants": [{ "constantsClassName": "com.power.doc.constants.RequestParamConstant" }], "sourceCodePaths": [ { "path": "src/main/java", "desc": "测试" } ] }
4、执行maven 插件
生成如下:
可立即提供给前端使用
5、链接
Smart-doc:https://gitee.com/sunyurepository/smart-doc
来源:oschina
链接:https://my.oschina.net/mdxlcj/blog/4356676