swagger生成文档初步使用

在大部分情况下,公司都会要求提供详细的接口文档,对于开发来说,文档有时候在赶进度的情况下,也是一件头疼的事.而swagger的自动生成文档功能,就可以帮助我们减少工作量,对于文档的修改也可以在代码中随时修改,对于项目比较急的项目也不失为一种好的解决方案.

  对于springboot项目,需要引入相关依赖

相关依赖为我们提供了可视化文档界面,并且支持文档的导出.

  我们也需要加入相关的配置,spring boot一般推荐使用注解配置的形式,不推荐使用xml形式,所以在此添加config配置类.

在此配置类里面,我们增加了ui界面的一些主页信息,在Bean的配置中,需要添加文档注解的扫描路径,这样我们的注解才能够被扫描解析到

在spring boot的启动类上开启swagger的自动配置 使用注解@EnableSwagger2

由此spring boot就集成了swagger2.接下来我们可以一个demo测试接口文档的生成.

我们的参数可能直接使用vo来接收,我们可以创建一个User实体类

最后一步,我们通过访问 http://localhost:8080/doc.html地址,我们就可以看到这样一个界面,由此就集成了一个简单的swagger.对于swagger的注解还有很多,有兴趣的可以搜索一下注解的各种用法,满足我们的日常开发.

https://www.imdb.com/list/ls080822331/?mode=desktop
https://www.imdb.com/list/ls080822325/?mode=desktop
https://www.imdb.com/list/ls080822340/?mode=desktop
https://www.imdb.com/list/ls080822397/?mode=desktop
https://www.imdb.com/list/ls080822399/?mode=desktop
https://www.imdb.com/list/ls080822605/?mode=desktop
https://www.imdb.com/list/ls080822604/?mode=desktop
https://www.imdb.com/list/ls080822615/?mode=desktop
https://www.imdb.com/list/ls080822637/?mode=desktop
https://www.imdb.com/list/ls080822664/?mode=desktop
https://www.imdb.com/list/ls080822621/?mode=desktop
https://www.imdb.com/list/ls080822642/?mode=desktop
https://www.imdb.com/list/ls080822691/?mode=desktop
https://www.imdb.com/list/ls080822689/?mode=desktop
https://www.imdb.com/list/ls080822204/?mode=desktop
https://www.imdb.com/list/ls080822212/?mode=desktop
https://www.imdb.com/list/ls080822239/?mode=desktop
https://www.imdb.com/list/ls080822222/?mode=desktop
https://www.imdb.com/list/ls080822249/?mode=desktop
https://www.imdb.com/list/ls080822281/?mode=desktop
https://www.imdb.com/list/ls080822288/?mode=desktop
https://www.imdb.com/list/ls080822455/?mode=desktop
https://www.imdb.com/list/ls080822458/?mode=desktop
https://www.imdb.com/list/ls080822410/?mode=desktop
https://www.imdb.com/list/ls080822418/?mode=desktop
https://www.imdb.com/list/ls080822439/?mode=desktop
https://www.imdb.com/list/ls080822469/?mode=desktop
https://www.imdb.com/list/ls080822497/?mode=desktop
https://www.imdb.com/list/ls080822481/?mode=desktop
https://www.imdb.com/list/ls080822903/?mode=desktop
https://www.imdb.com/list/ls080822955/?mode=desktop
https://www.imdb.com/list/ls080822979/?mode=desktop
https://www.imdb.com/list/ls080822912/?mode=desktop
https://www.imdb.com/list/ls080822963/?mode=desktop
https://www.imdb.com/list/ls080822927/?mode=desktop
https://www.imdb.com/list/ls080822990/?mode=desktop
https://www.imdb.com/list/ls080822987/?mode=desktop
https://www.imdb.com/list/ls080822802/?mode=desktop
https://www.imdb.com/list/ls080822855/?mode=desktop
https://www.imdb.com/list/ls080822810/?mode=desktop
https://www.imdb.com/list/ls080822818/?mode=desktop
https://www.imdb.com/list/ls080822862/?mode=desktop

 

你可能感兴趣的:(springboot)