配置文件
/**
* swagger配置
*/
@EnableSwagger2
@Configuration
public class Swagger2Config {
@Bean
public Docket createReviewRestApi() {
ArrayList<Parameter> params = Lists.newArrayList();
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)).paths(PathSelectors.any()).build()
.globalOperationParameters(Lists.newArrayList(
new ParameterBuilder().parameterType("header").name("at").description("访问令牌")
.modelRef(new ModelRef("string")).build())).globalResponseMessage(RequestMethod.GET, Lists
.newArrayList(
new ResponseMessage(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), new ModelRef("string"),
new HashMap<>(), null))).globalResponseMessage(RequestMethod.POST, Lists.newArrayList(
new ResponseMessage(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), new ModelRef("string"),
new HashMap<>(), null))).globalResponseMessage(RequestMethod.PUT, Lists.newArrayList(
new ResponseMessage(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), new ModelRef("string"),
new HashMap<>(), null))).globalResponseMessage(RequestMethod.DELETE, Lists.newArrayList(
new ResponseMessage(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), new ModelRef("string"),
new HashMap<>(), null))).globalOperationParameters(params).groupName("投资会议系统");
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("投资会议系统接口文档").description("投资会议系统接口文档").version("1.0.0").build();
}
}
swagger和UI模块依赖
<!-- swagger begin -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>2.0.3</version>
</dependency>
<!-- swagger end -->
效果图:
(仅供参考!)