編寫和維護(hù)接口文檔是每個(gè)程序員的職責(zé)窒升,根據(jù) Swagger2 可以快速幫助我們編寫最新的 API 接口文檔,間接提升了團(tuán)隊(duì)開發(fā)的溝通效率慕匠。
swagger UI 使用方法
在 pom.xml 中引入依賴
<dependency>
<groupId>com.spring4all</groupId>
<artifactId>swagger-spring-boot-starter</artifactId>
<version>1.8.0.RELEASE</version>
</dependency>
在應(yīng)用主類中增加 @EnableSwagger2Doc 注解
@SpringBootApplication
@MapperScan("com.springboot.mybatis.mapper")
@EnableSwagger2Doc
public class SpringBootMybatisApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootMybatisApplication.class, args);
}
}
默認(rèn)情況下就能產(chǎn)生所有當(dāng)前 SpringMVC 加載的請(qǐng)求映射文檔饱须。
訪問地址:http://localhost:8080/swagger-ui.html
在配置文件中添加 swagger2 配置
swagger.enabled=true
swagger.title=spring-boot-mybatis module api
swagger.description=Starter for swagger 2.x
swagger.license=Apache License, Version 2.0
swagger.licenseUrl=https://www.apache.org/licenses/LICENSE-2.0.html
swagger.termsOfServiceUrl=https://github.com/dyc87112/spring-boot-starter-swagger
swagger.contact.name=(此處自行填寫name)
swagger.contact.url=(此處自行填寫url地址)
swagger.contact.email=(此處自行填寫email)
swagger.base-package=com.springboot.mybatis.controller
swagger.base-path=/**
swagger.exclude-path=/error, /ops/**
swagger UI 整體效果
更多特性請(qǐng)移步該項(xiàng)目:github地址