Alternatives to Swagger are more advanced

The following writing is simple, clear and unambiguous, and go straight to the dry goods:

1. It is troublesome for programmers to write interface documents. The first is access path, request method, request parameter, request list, request parameter instance, return result, return result type, return structure, return structure instance, return parameter list, return status code List waiting etc. . . There's too much going on, it's crazy

As a result, there is an online Swagger document. What needs to be paid attention to in this document is: the suffix difference input before and after version 3.0, before → swagger-ui.html, after → swagger-ui/index.html, and the interface of the version is like this:

Such:Although it is very detailed, if you add something in the background, it will inevitably cause individual parameters of the page (

Example Value) is missing, it needs to be filled in manually, it is indeed a bit blue and thin mushrooms;

2. Now I found a better one than swagger2. You can directly download pdf, word, html, and md documents. Isn't it very advanced? Although it is also used for the first time, record it to keep everyone fresh and fresh. This premise is also in swagger: knife4j

His interface is like this:


and this:

The exported md looks like this:


Is it a bright spot for people? When we go back to the front end and come back to the back end to test the code, we can finally be tough. This is the document, thank you for taking it away, hehe

3. After talking so much, are you drooling? Go directly to the code: Generally knife4j belongs to the common public class, so you need to create a knife4j in common (write the package name casually, you can understand it yourself) and then it depends on whether your C/V Dafa is powerful and needs to be declared Yes: the difference between swagger and knife4j is this annotation: @EnableKnife4j

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

public class SwaggerConfiguration {

    public Docket buildDocket() {
        return new Docket(DocumentationType.SWAGGER_2)

    private ApiInfo buildApiInfo() {
        Contact contact = new Contact("programmer", "", "");
        return new ApiInfoBuilder()
                .title("headlines-Platform management API Documentation Knife4j")
                .description("Platform management service api")


 The common public class has been completed, then it is time to scan the project that inherits the public class, but the two packages are a bit far apart. How to let the admin scan the knife4j in the common, we need to create a config package in the admin, and then Create a knife4j entity class, then add the @configuration annotation above the class, add a package scan: @ComponentScan("com.package name.knife4j"), note: the absolute path of knife4j in common

The full version is like this, then you can start the project and visit the address: http://localhost:8080/doc.html

go try it now




Tags: Java servlet programming language

Posted by GYK on Sun, 09 Oct 2022 22:16:32 +0530