作为一个天秤座的程序员,虽然很早就知道 swagger,并且也知道它的好处,但是无法忍受那丑陋的显示界面,所以以前一直都采用markdown来书写api文档,前一段时间逛逛码云发现了swagger-bootstrap-ui这个好东西,生成api文档真的是简洁美观。
Swagger-Bootstrap-UI是Swagger的前端UI实现,采用jQuery+bootstrap实现,目的是替换Swagger默认的UI实现Swagger-UI,使文档更友好一点儿...。Swagger-Bootstrap-UI项目地址https://git.oschina.net/xiaoym/swagger-bootstrap-ui
依赖配置:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.2.2</version>
</dependency>
<!--swagger-bootstrap-ui-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.6</version>
</dependency>
如果项目采用SpringBoot则直接参考swagger-bootstrap-ui提供的demo,其实Spring MVC项目使用swagger-bootstrap-ui也差不多,只需要在Spring mvc的xml中加入下面两行配置,其他完全相同,改代码是让项目自动去扫描swagger-bootstrap-ui的controller
<context:component-scan base-package="springfox.petstore.controller"/>
<bean name="applicationSwaggerConfig" class="com.hunnao.config.SwaggerConfiguration"/>
SwaggerConfiguration类也是来自swagger-bootstrap-ui下的说明,然后在controller接口层加注解参考swagger-bootstrap-ui提供的demo即可