swgger使用
- 编写swgger配置类
@Configuration
@EnableSwagger2
public class SwggerConfig {
@Bean
public Docket webApiConfig(){
return new Docket(DocumentationType.SWAGGER_2)
.groupName("webApi")
.apiInfo(webApiInfo())
.select()
.paths(Predicates.not(PathSelectors.regex("/admin/.*")))
.paths(Predicates.not(PathSelectors.regex("/error.*")))
.build();
}
private ApiInfo webApiInfo(){
return new ApiInfoBuilder()
.title("网站-课程中心API文档")
.description("本文档描述了课程中心微服务接口定义")
.version("1.0")
.contact(new springfox.documentation.service.Contact("Helen", "http://atguigu.com", "myc957@126.com"))
.build();
}
}
- 使用swgger
@RestController
@RequestMapping("/eduservice/edu-teacher")
@Api(description ="讲师管理")
public class EduTeacherController {
@Autowired
private EduTeacherService eduTeacherService;
//http://localhost:8001/eduservice/edu-teacher/findAll
@DeleteMapping("{id}")
@ApiOperation(value="删除一个讲师")
public boolean deleteTeacher(@ApiParam(name = "id",value ="讲师ID",required = true) @PathVariable String id)
{
boolean removeById = eduTeacherService.removeById(id);
return removeById;
}
}
- swgger注解使用
@Api(description =“讲师管理”)使用在类上面
@ApiOperation(value = “查询所有讲师”)使用在方法上面介绍方法的含义
@@ApiParam(name = “id”,value =“讲师ID”,required = true) 使用在参数里边 ,介绍方法使用参数的含义是否必录。
swgger 地址:http://localhost:8001/swagger-ui.html