swagger-bootstrap-ui is a UI implemented based on the swagger interface API. Since swagger native ui has an upper and lower structure, it is not very clear when browsing the interface. Therefore, swagger-bootstrap-ui is based on the left and right menu style, which is similar to the style of left and right structures in the development backend system, which is convenient for browsing with the interface.
GitHub: https://github.com/xiaoymin/Swagger-Bootstrap-UI
Interface preview:
Introduce swagger
Introduce swagger and ui's jar package dependencies in pom.xml file
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.7.0</version></dependency><!--Introducing ui package--><dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>swagger-bootstrap-ui</artifactId> <version>1.7</version></dependency>
Configure configuration
Configure the enable configuration file of swagger, key annotation @EnableSwagger2
The following configuration is a configuration that supports interface grouping. If there is no grouping configuration, you only need to create a Docket.
@Configuration@EnableSwagger2public class SwaggerConfiguration { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .groupName("Resource Management") .select() .apis(RequestHandlerSelectors.basePackage("com.lishiots.dc.baseinfo.ctl")) .paths(PathSelectors.any()) .build(); } @Bean public Docket createMonitorRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .groupName("Real-time Monitoring") .select() .apis(RequestHandlerSelectors.basePackage("com.lishiots.dc.monitor.ctl")) .paths(PathSelectors.any()) .build(); } @Bean public Docket createActivitiRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .groupName("Workflow Engine") .select() .apis(RequestHandlerSelectors.basePackage("com.lishiots.dc.activiti.ctl")) .paths(PathSelectors.any()) .build(); } @Bean public Docket createBaseRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .groupName("kernel module") .select() .apis(RequestHandlerSelectors.basePackage("com.lishiots.dc.kernel.ctl")) .paths(PathSelectors.any()) .build(); } @Bean public Docket createComplaintRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .groupName("Complaint Management") .select() .apis(RequestHandlerSelectors.basePackage("com.lishiots.dc.complaint.ctl")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("swagger RESTful APIs") .description("swagger RESTful APIs") .termsOfServiceUrl("http://www.test.com/") .contact("[email protected]") .version("1.0") .build(); }}Controller layer uses swagger annotation
ctl code layer:
@Api(tags = "banner management")@RestController@RequestMapping("/api/bannerInfo")public class BannerCtl { @Autowired private BannerInfoService service; @PostMapping("/query") @ApiOperation(value = "query banner",notes = "query banner") public Pagination<BannerInfo> bannerInfoQuery(){ Pagination<BannerInfo> pagination = service.bannerInfoQuery(); return pagination; }}Interface access
Enter in the browser: http://${host}:${port}/doc.html
Summarize
The above is the method of using swagger-bootstrap-ui in Spring Boot introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!