1.在pom.xml中加入依赖
<!-- Swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.0</version>
</dependency>
2.写Swagger2配置类
@Configuration
@EnableSwagger2
public class Swagger2Config {
@Bean
public Docket accessToken() {//核心配置
return new Docket(DocumentationType.SWAGGER_2).groupName("api")//定义组
.apiInfo(apiInfo())//定义项目说明
.select()//选择那些路径和api会生成document
.apis(RequestHandlerSelectors.basePackage("com.it.photography.controller"))//包路径
.build();//配置
}
/**
* http://localhost:8080/swagger-ui.html#/ //页面
*
* @return
*/
private ApiInfo apiInfo() {//定义项目说明
return new ApiInfoBuilder().title("项目").description("描述")
.termsOfServiceUrl("网址")
.contact(new Contact("姓名", "URL", "邮件")
).version("1.0").build();//版本号
}
}
3.在对应包下加注解@ApiOperation()
@PostMapping("/findUserInfo")
@ApiOperation(value = "用户信息查询", notes = "可查单个或全部,有权限控制")
public ResultData findUserInfo(@RequestBody User user) {
return userService.findUserInfo(user);
}
4.启动项目打开页面http://localhost:8080/swagger-ui.html
网友评论