swagger2的使用
1、相关依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
2、创建Swagger2配置文件
@Configuration
@EnableSwagger2
public class Swagger2Config {
@Bean
public Docket webApiConfig(){
return new Docket(DocumentationType.SWAGGER_2)
.groupName("webApi")
.apiInfo(webApiInfo())
.select()
.build();
}
private ApiInfo webApiInfo(){
return new ApiInfoBuilder()
.title("网站-课程中心API文档")
.description("本文档描述了课程中心微服务接口定义")
.version("1.0")
.contact(new Contact("Helen", "http://atguigu.com", "55317332@qq.com"))
.build();
}
}
美化swagger信息显示
@RestController
@RequestMapping("/province")
@Api(description = "省份信息接口")
public class ProvinceController {
@Autowired
private ProvinceService provinceService;
@Autowired
private ProvinceDao provinceDao;
@GetMapping("/{id}")
//@ApiOperation(value = "获取otp", notes="通过手机号获取OTP验证码")
public Province getOne(@PathVariable("id")Integer id){
Province one = provinceService.getProvinceById(id);
return one;
}