Use the swagger-bootstrap-ui method in Spring Boot,

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.