标签:查看 1.0 pat contact ide handle value pom 构建
一:创建SpringBoot ,在pom.xml文件中加入jar包
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
二:简历Swagger2的配置类
@EnableSwagger2 //注入swagger2
@Configuration //beans
public class SwaggerConfig {
@Bean //bean
public Docket createRestApi(){
return new Docket(DocumentationType.SWAGGER_2)
.groupName("apigrounp1")
.apiInfo(apiInfo())//组名
.select()//选择那些路劲和api生成document
.apis(RequestHandlerSelectors.basePackage("com.hp.springbootswagger.controller"))
.paths(PathSelectors.any())//对所有路劲渐行监控
.build();
}
//构建api文档的详细信息方法
public ApiInfo apiInfo(){
return new ApiInfoBuilder()
.title("Spring boot测试使用Swagger2构建RestFulApi")//页面标题
.contact(new Contact("浩明","https://www.baidu.com","1343876119@qq.com"))//创建人
.version("1.0")//版本号
.description("API描述")//api描述
.build();//构建
}
}
三:controller层:result风格
@Api(value="person" ,description="针对用户的插入,删除,查看等操作")
类上面:
@ApiOperation(value ="创建用户",notes = "根据用户User创建用户")
@ApiImplicitParams({
@ApiImplicitParam(dataType = "java.long.Lang",paramType = "path",name = "id",value = "id",required = true),
@ApiImplicitParam(dataType = "User",name = "user",value = "用户",required = true)
})
方法上:
四:swagger2的相关注解的解释如下:
swagger-ui页面请求:http://localhost:8080/swagger-ui.html
[idea] SpringBoot整合swagger2实现CRUD
标签:查看 1.0 pat contact ide handle value pom 构建
原文地址:https://www.cnblogs.com/yhm9/p/10513624.html