Wrapper 可以生成一个在线的文档,并且可以在里面方便的进行Rest风格测试
maven
<!--swagger--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <scope>provided </scope> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <scope>provided </scope> </dependency>
编写config配置类
直接拷贝,改关键信息即可,该类要被springboot扫描到
@Configuration @EnableSwagger2 public class SwaggerConfig { @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 Contact("java", "http://acdongla.cc", "wyiheyes@163.com")) .build(); } }
浏览器进入/swagger-ui.htm
进入界面
使用注解即可
@Api(description = "讲师管理")
定义在类上
@ApiOperation("查询所有讲师信息")
定义在方法上
@ApiParam(name = "id", value = "讲师id", required = true)
定义在参数上
效果如图