Introduction to the

Knife4j is an enhanced version of Swagger-UI. Previously, Swagger’s front-end page was not friendly enough, but now there is an enhanced version of Swagger.

github

MAVEN

< the dependency > < groupId > IO. Springfox < / groupId > < artifactId > springfox - swagger2 < / artifactId > < version > 2.9.2 < / version > </dependency> // UI interface will be different before version 2.0 <! -- https://mvnrepository.com/artifact/com.github.xiaoymin/knife4j-spring-ui --> <dependency> < the groupId > com. Making. Xiaoymin < / groupId > < artifactId > knife4j - spring - UI < / artifactId > < version > 2.0.0 < / version > < / dependency >Copy the code

Writing configuration classes

@Configuration
@EnableSwagger2
public class SwaggerConfiguration {


    @Bean
    public Docket docket(a) {
        return new Docket(DocumentationType.SWAGGER_2)
                // Implement development and production environments through configuration
                .enable(true)
                .apiInfo(new ApiInfoBuilder()
                        .title("knife4j Restful Apis")
                        .description("this is a description")
                        .termsOfServiceUrl("http://localhost:8080/")
                        .contact("[email protected]")
                        .version("0.0.1")
                        .build()
                )
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.jl.spring2")) .paths(PathSelectors.any()) .build(); }}Copy the code

The effect

Access localhost: 8080 / doc. HTML.

  • Effect of the home page
  • Effect of interface

The annotations are the same as Swagger, but the author intends to write his own annotations. This UI looks a lot more comfortable, and you can debug yourself.

OVER