【Spring*】Integrated swagger

springboot

Configuration:

Create a new swagger class in the same directory of the entry class *application:

@Configuration
@EnableSwagger2
public class Swagger2 {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo (apiInfo ())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.demo"))//Modify to your own package
                .paths(PathSelectors.any())
                .build();
    }
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Building RESTful APIs with Swagger2 in Spring Boot")
                .version("1.0")
                .build();
    }
}

The default is to display all Controllers configured with @RequestMapping

swagger corresponds to annotations:

@Api: Mark the Controller as a Swagger documentation resource.

@ApiOperation: describe a method of a class, or an interface

@ApiImplicitParams : multiple parameter descriptions
@ApiImplicitParam: single parameter description

@ApiModel: use an object to receive parameters

@ApiModelProperty: When receiving parameters with an object, describe a field of the object
https://blog.csdn.net/Eacter/article/details/55261756

https://blog.csdn.net/winter_chen001/article/details/78330687

spring配置swagger

1. Introducing the web project pom file

<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. Add in the configuration file of 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真真滴是很强大



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325664592&siteId=291194637