1.项目引入依赖
<!-- swagger --> <dependency> <groupId>com.spring4all</groupId> <artifactId>swagger-spring-boot-starter</artifactId> </dependency>2.bootstrap.yml 或application.yml中增加配置
swagger: enabled: true # 是否生成swagger文档 title: OS order # 随意 description: OS order接口文档 # 随意 version: V1.0 base-package: com.css.cloud.cnposprod.controller #(这里是指controller里的包) # base-path: /api # swagger会解析的URL规则,默认所有 exclude-path: /test/** # 在base-path基础上需要排除的URL规则、3.增加配置类
@Configuration class WebMvcConfig extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("swagger-ui.html") .addResourceLocations("classpath:/META-INF/resources/"); registry.addResourceHandler("/webjars/**") .addResourceLocations("classpath:/META-INF/resources/webjars/"); } }4.在启动(main)类上增加注解@EnableSwagger2Doc
5.对应的controller类上加@Api(value = “ProdController”, tags = {“O2O”}, description = “O2O,搜寻”),在controller类的方法上加@ApiOperation(value = “获取产品列表”) ,具体注解用法自行百度。
6.输入网址后可以看到文档