在Spring Boot中使用swagger-bootstrap-ui的方法
swagger-bootstrap-ui 是基于swagger接口api實(shí)現(xiàn)的一套UI,因swagger原生ui是上下結(jié)構(gòu)的,在瀏覽接口時(shí)不是很清晰,所以, swagger-bootstrap-ui 是基于左右菜單風(fēng)格的方式,適用與我們?cè)陂_(kāi)發(fā)后臺(tái)系統(tǒng)左右結(jié)構(gòu)這種風(fēng)格類似,方便與接口瀏覽
GitHub: https://github.com/xiaoymin/Swagger-Bootstrap-UI
界面預(yù)覽:
引入swagger
在pom.xml文件中引入swagger以及ui的jar包依賴
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.7.0</version> </dependency> <!--引入ui包--> <dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>swagger-bootstrap-ui</artifactId> <version>1.7</version> </dependency>
配置configuration
配置swagger的啟用配置文件,關(guān)鍵注解 @EnableSwagger2
一下配置是支持接口分組的配置,如果沒(méi)有分組配置,只需要?jiǎng)?chuàng)建一個(gè) Docket 即可
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.groupName("資源管理")
.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("實(shí)時(shí)監(jiān)測(cè)")
.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("工作流引擎")
.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模塊")
.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("投訴管理")
.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();
}
}
Controller層使用swagger注解
ctl代碼層:
@Api(tags = "banner管理")
@RestController
@RequestMapping("/api/bannerInfo")
public class BannerCtl {
@Autowired
private BannerInfoService service;
@PostMapping("/query")
@ApiOperation(value = "查詢banner",notes = "查詢banner")
public Pagination<BannerInfo> bannerInfoQuery(){
Pagination<BannerInfo> pagination = service.bannerInfoQuery();
return pagination;
}
}
接口訪問(wèn)
在瀏覽器輸入: http://${host}:${port}/doc.html
總結(jié)
以上所述是小編給大家介紹的在Spring Boot中使用swagger-bootstrap-ui的方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
SpringBoot實(shí)現(xiàn)微服務(wù)通信的多種方式
微服務(wù)通信是指在分布式系統(tǒng)中,各個(gè)微服務(wù)之間進(jìn)行數(shù)據(jù)交互和通信的過(guò)程,今天我們將探討在Spring Boot中實(shí)現(xiàn)微服務(wù)通信的多種方式,文章通過(guò)代碼示例給大家介紹的非常詳細(xì),需要的朋友可以參考下2024-07-07
簡(jiǎn)單了解Mybatis如何實(shí)現(xiàn)SQL防注入
這篇文章主要介紹了簡(jiǎn)單了解Mybatis如何實(shí)現(xiàn)SQL防注入,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-01-01
Java任務(wù)定時(shí)執(zhí)行器案例的實(shí)現(xiàn)
定時(shí)器會(huì)執(zhí)行指定的任務(wù),本文主要介紹了Java任務(wù)定時(shí)執(zhí)行器案例的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06
SpringBoot+Eureka實(shí)現(xiàn)微服務(wù)負(fù)載均衡的示例代碼
這篇文章主要介紹了SpringBoot+Eureka實(shí)現(xiàn)微服務(wù)負(fù)載均衡的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11
SpringSecurity OAtu2+JWT實(shí)現(xiàn)微服務(wù)版本的單點(diǎn)登錄的示例
本文主要介紹了SpringSecurity OAtu2+JWT實(shí)現(xiàn)微服務(wù)版本的單點(diǎn)登錄的示例,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05
J2SE基礎(chǔ)之在Eclipse中運(yùn)行hello world
本文的內(nèi)容非常的簡(jiǎn)單,跟隨世界潮流,第一個(gè)Java程序輸出“Hell World!”。希望大家能夠喜歡2016-05-05

