spring boot配置knife4j

1.pom文件加入knife4j依赖
#包含spring mvc依赖
< dependency>
< groupId>org.springframework.boot
< artifactId>spring-boot-starter-web
< /dependency>
#knife4j依赖
< dependency>
< groupId>com.github.xiaoymin
< artifactId>knife4j-spring-boot-starter
< version>3.0.2
< /dependency>
2.配置knife4j
@Configuration
@EnableSwagger2
@EnableKnife4j
public class SwaggerConfiguration {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2) //文档版本
.apiInfo(apiInfo()) //api配置对象,下方有实现。
.select()
.apis(RequestHandlerSelectors.basePackage(“com.shuaih.haha”)) //api所在路径,即controller层所在包
.paths(PathSelectors.any()) //请求路径此处配置的所有路径等同于/*。
.build();

}
 
 // api对象
private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
            .title("swagger-bootstrap-ui RESTful APIs")  //文档头部
            .description("swagger-bootstrap-ui")  //文档描述
            .termsOfServiceUrl("http://localhost:8080/")  //服务地址
            .version("1.0")  //版本
            .build();
}

}

3.启动项目,浏览器访问http://localhost:8080/doc.html#
效果图

4.swagger注解
@Api(value = “登录服务”,description = “用户登录相关接口”)
Api 用在Controller中,标记一个Controller作为swagger的文档资源

@ApiOperation(value = “获取验证码图片”,notes = “每调用一次,就会随机生成一张验证码图片”,response = String.class)
ApiOperation 该注解用在Controller的方法中,用于注解接口

@ApiParam(name = “param”,value = “实体类AclParam”,required = true)
ApiParam 该注解用在方法的参数中。

@ApiResponses({
@ApiResponse(code = 200,message = “成功!”),
@ApiResponse(code = 401,message = “未授权!”),
@ApiResponse(code = 404,message = “页面未找到!”),
@ApiResponse(code = 403,message = “出错了!”)
})
ApiResponses/ApiResponse 该注解用在Controller的方法中,用于注解方法的返回状态。

@ApiModel(value = “用户信息类”,description = “用户信息”)
ApiModel 该注解用在实体类中。

@ApiModelProperty(name = “count”,value = “查询数量”,notes = “返回信息的条数”)
ApiModelProperty 该注解用在实体类的字段中。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值