swagger2
swagger2
- 依赖 ```xml
2. 创建Java配置类
```java
package com.xiaokong.usercenter.common;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class Swagger2Config {
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
// @Bean
// public Docket createRestApi() {
// return new Docket(DocumentationType.SWAGGER_2)
// .apiInfo(apiInfo())
// .select()
// // 指定controller存放的目录路径
// .apis(RequestHandlerSelectors.basePackage("com.digag.web"))
// .paths(PathSelectors.any())
// .build();
// }
//
// private ApiInfo apiInfo() {
// return new ApiInfoBuilder()
// // 文档标题
// .title("usercenter")
// // 文档描述
// .description("用户中心项目接口文档")
// .termsOfServiceUrl("http://47.97.184.82:23250")
// .version("v1")
// .build();
// }
}
- 在controller里面配置接口注释
@RestController @RequestMapping("/landlordUser") @Api(tags = "landlordUser") //api注解 public class UserController { // 省略其他内容 // 根据手机号查询用户的id和是否认证,如果认证了公司,则返回公司id和公司名称 @ApiOperation(value="获取用户", notes="根据url的手机号来获取用户认证信息") //api注解 @ApiImplicitParam(name = "phoneNum",value = "手机号",example = "15924133142") //api注解 @RequestMapping(value = "/getUser/{phoneNum}", method = RequestMethod.GET) public Result getUser(@PathVariable("phoneNum") String phoneNum) { // 省略其他内容 return new Result<>(resu); } }
- 访问http://localhost:8080/swagger-ui.html即可看到所有接口;不用写api注解的接口也会列出;写注解是为了备注???
Comments
Leave a comment