When making crMEb-Java open source mall system, our team used UNI-App, which is also a popular mobile terminal development technology, which involves the separation of front and back ends. Generally, Swagger will be used when developing front and back end separation projects using JAVA. Swagger is a framework for generating, describing, invoking, and visualizing RESTful Web API services. Swagger makes it easy to deploy and manage powerful apis, but only in small projects with few APIS.
As the,CRMEB-JAVA open source mall systemOptimize ceaselessly, the increasing function of, and Taiwan before and after separation were done before and after the end, the interface number once exceeded more than 200, which makes some experience in the system become worse and worse, such as: format for JSON can’t submit parameters, parameter wrong looking for trouble, return the result can’t fold, is too long can’t see, really very painful!
Knife4j: Swagger knife4J: Swagger knife4J: Swagger knife4J: Swagger knife4J: Swagger knife4J: Swagger knife4J: Swagger knife4J: Swagger knife4J: Swagger knife4J
We want Knife4J to be small, lightweight, and powerful as a dagger, and we want it to be a universal solution for Swagger interface documentation, not just a front-end Ui front end.
Here’s a sneak peek of Knife4J optimized Swagger on the project:
The most important thing is that the search box can search the relevant API interface for quick query, and can debug the interface online, and then come to a picture to show!
Knife4j Open-source project description:
The structure is described as follows:
The name of the module | instructions |
---|---|
knife4j | Integrate Swagger’s enhanced solution for the Java MVC framework, as detailed in the introduction notes above |
knife4j-admin | Swagger interface document registry center in the Cloud, integration Gateway integrates any microservice documents. The development of this module has not been started yet |
knife4j-extension | Chrome enhanced Swagger interface document UI, fast rendering Swagger resources, this module has not started development |
knife4j-service | A series of interface services for Swagger, the module has not yet started development |
knife4j-front | A pure front-end static version of Knife4J-Spring-UI for integration with non-Java languages. Development of this module has not yet started |
knife4j-vue | This module is the source module of knife4J front end, which is developed based on Vue framework. Knife4j-spring-ui files are packaged and built using this module |
swagger-bootstrap-ui | Knife4j’s predecessor, last released version 1.9.6 |
swagger-bootstrap-ui-front | Swagger-bootstrap-ui is a pure front-end version of swagger-Bootstrap-UI, which is based on the 1.9.3 branch and can be used by other development languages |
The Spring Boot project uses KNIfe4J
- Official DOM: knife4J-spring-boot-demo
- Study CRMEB_JAVA open source mall system, learn to see in the actual development, how to integrate into the project!
Maven reference
The first step is to introduce the Knife4J dependencies in the project’s POM.xml file as follows:
<dependencies> <dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>knife4j-spring-boot-starter</artifactId> <! -- Search for the latest version number in Maven's central repository when referencing.2.02.</version>
</dependency>
</dependencies>
Copy the code
If you want to import using BOM, please refer to Maven BOM reference
Create a Swagger profile
New Swagger SwaggerConfiguration configuration file. The Java files, create springfox provide Docket grouping objects, the code is as follows:
@Configuration @EnableSwagger2 @EnableKnife4j @Import(BeanValidatorPluginsConfiguration.class) public class SwaggerConfiguration { @Bean(value = "defaultApi2") public Docket defaultApi2() { Docket docket=new Docket (DocumentationType SWAGGER_2). ApiInfo (apiInfo ()) / / group name. The groupName (" 2 X version "). The select () / / Controller scan packages specified path here .apis(RequestHandlerSelectors.basePackage("com.swagger.bootstrap.ui.demo.new2")) .paths(PathSelectors.any()) .build(); return docket; }}Copy the code
The above two notes need special explanation, as shown in the following table:
annotations | instructions |
---|---|
@EnableSwagger2 | This annotation is provided by the Springfox-Swagger framework to use the Swagger annotation, which must be added |
@EnableKnife4j | Knife4j is an enhanced annotation provided by KNIfe4J. Ui provides enhancements such as dynamic parameters, parameter filtering, interface sorting, etc. You must add this annotation if you want to use these enhancements, otherwise you don’t need to |
access
- Enter the address in your browser:
http://host:port/doc.html
- Click to enter CRMEB-JAVA open source mall project to learn: Gitee project address
Thank you for reading. If you find it helpful, please follow the CRMEB Nuggets. Code cloud has our open source mall project, knowledge payment project, are based on PHP+ Vue +mysql development, learning and research welcome to use, we can move rich little hands Start oh, pay attention to me not lost!