springboot
配置:
在入口类*application的同级目录下新建swagger的类:
@Configuration
@EnableSwagger2
public class Swagger2 {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.demo"))//对应修改成自己的包
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Spring Boot中使用Swagger2构建RESTful APIs")
.version("1.0")
.build();
}
}
默认是会显示所有配置了@RequestMapping的Controller
swagger对应有注解:
@Api:将Controller标记为Swagger文档资源。
@ApiOperation:描述一个类的一个方法,或者说一个接口
@ApiImplicitParams :多个参数描述
@ApiImplicitParam:单个参数描述
@ApiModel:用对象来接收参数
@ApiModelProperty:用对象接收参数时,描述对象的一个字段
https://blog.csdn.net/Eacter/article/details/55261756https://blog.csdn.net/winter_chen001/article/details/78330687
spring配置swagger
1、web项目pom文件引入
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.5.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.5.0</version> </dependency>2、 Springmvc的配置文件里添加
<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/> <mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/> <bean class="springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration" id="swagger2Config"/>
行为分析的项目是这么配置的,记得还有一个文件但是没有找到,起项目打开swagger也打开了,那就是这样配置吧
调试发现了这个:感觉idea真真滴是很强大