做为一个天秤座的程序员,虽然很早就知道 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-uijava
依赖配置:git
<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便可github