Springboot整合swagger2,包括修改swagger可视化界面和界面汉化处理

本文介绍了如何在Springboot项目中整合swagger2,包括详细步骤:配置swagger类,引入所需jar包,并通过修改资源文件实现swagger UI的中文显示和自定义接口展示界面。
摘要由CSDN通过智能技术生成

Springboot整合swagger2,包括修改swagger可视化界面和界面汉化处理

swagger配置类编写

package com.ruiec.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**

- swagger配置类

- @author luo_wei<br>

- @date 2019年5月8日 下午2:13:17
  */
  @Configuration
  //@EnableSwagger2 //启用Swagger2
  public class SwaggerApi {

  /**

  - 创建Docket的Bean之后
  - @author luo_wei<br>
  - @date 2019年5月8日 下午2:10:26
    */
    @Bean
    public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().
    		apis(RequestHandlerSelectors.basePackage("com.ruiec.controller")).paths(PathSelectors.any()).build();
    }
    /**
  - 创建该Api的基本信息(这些基本信息会展现在文档页面中)
  - @ApiIgnore无视
  - @author luo_wei<br>
  - @date 2019年5月8日 下午2:10:32
    */
    @SuppressWarnings("deprecation")
    private ApiInfo apiInfo() {
    return new ApiInfoBuilder().title("大数据BI-JAVA部门对接项目").description("BI-前端api接口界面")
    		.termsOfServiceUrl("http://192.168.20.215:8081/swagger-ui.html").contact("罗巍").version("1.0.0").build();
    }

}

jar包引入

	<!-- 默认swagger-ui展示界面 -->
	<dependency>
		<groupId>io.springfox</groupId>
		<artifactId>springfox-swagger-ui</artifactId>
		<version>2.7.0</version>
	</dependency>
	<dependency>
		<groupId>org.reflections</groupId>
		<artifactId>reflections</artifactId>
		<version>0.9.11</version>
	</dependency>

src\main\r

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值