Swagger
通过docket进行设置配置swagger,里面要的东西都可自己new一个类似的对象然后放进去
例如这个apiInfo对象
package com.***.config;
import org.springframework.beans.factory.annotation.Value;
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;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Value("${swagger2.enable}")
private Boolean swagger2Enable;
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.enable(swagger2Enable)
.pathMapping("/")
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.***"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("*** Api Document")
.version("1.0.0")
.build();
}
}
方法参数案例:
@ApiOperation(value = "接口总体描述", notes = "详细描述: 方法详细描述信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "username", value = "用户名", dataType = "String", defaultValue = "qlh"),
@ApiImplicitParam(name = "password", value = "密码", dataType = "String", defaultValue = "123")
})
@PostMapping("/")
public String login(String username, String password) {
return "Hello login ~";
}