Use the swagger-bootstrap-ui method in Spring Boot,
Swagger-bootstrap-ui is a set of UIS implemented based on the swagger api. Because the swagger native UI is in the upper and lower structure, it is not very clear when Browsing interfaces, swagger-bootstrap-ui is based on the left and right menu style. It is applicable to the style similar to the left and right structure of the system in the development background, which is convenient for browsing with interfaces.
GitHub: https://github.com/xiaoymin/Swagger-Bootstrap-UI
Interface preview:
Introduce swagger
Introduce the swagger and ui jar package dependencies in the pom. xml file.
<Dependency> <groupId> io. springfox </groupId> <artifactId> springfox-swagger2 </artifactId> <version> 2.7.0 </version> </dependency> <! -- Introduce the ui package --> <dependency> <groupId> com. github. xiaoymin </groupId> <artifactId> swagger-bootstrap-ui </artifactId> <version> 1.7 </version> </dependency>
Configure configuration
Configure the swagger enable configuration file, key annotation @ EnableSwagger2
The following configuration supports the interface group configuration. If there is no group configuration, you only need to create a Docket.
@ Configuration @ EnableSwagger2public class SwaggerConfiguration {@ Bean public Docket createRestApi () {return new Docket (DocumentationType. SWAGGER_2 ). 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 ()). 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 ()). 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 ()). 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 ()). 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 ("xiaoymin@foxmail.com "). version ("1.0 "). build ();}}
The Controller layer uses the 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 http: // $ {host }:$ {port}/doc.html in the browser.
Summary
The above section describes how to use swagger-bootstrap-ui in Spring Boot. I hope it will help you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!