Spring Boot Swagger2使用方法过程解析

网友投稿 267 2022-11-26


Spring Boot Swagger2使用方法过程解析

1.添加Swagger2依赖

io.springfox

springfox-swagger2

2.2.2

io.springfox

springfox-swagger-ui

2.2.2

2配置类

@Configuration

@EnableSwagger2

public class Swagger2 {

@Bean

public Docket createRestApi() {

return new Docket(DocumentationType.SWAGGER_2)

.apiInfo(apiInfo())

.select()

.apis(RequestHandlerSelectors.basePackage("com.bs.swaggertest.controller"))

.paths(PathSelectors.any())

.build();

}

private ApiInfo apiInfo() {

return new ApiInfoBuilder()

.title("微信项目接口对接文档")

.description("测试环境接口调试")

http:// .contact("陶海军")

.version("1.0")

.build();

}

}

3.添加文档内容

@RestController

@RequestMapping(value="/users")

public class UserController {

@ApiOperation(value="删除用户", notes="根据url的id来指定删除对象")

@ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "String")

@RequestMapping(value="/{id}", method=RequestMethod.DELETE)

public String deleteUser(@PathVariable String id) {

return "suchttp://cess";

}

}

4.测试

http://localhost:8080/swagger-ui.html


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:java8 LocalDate 使用详解
下一篇:java SpringBoot自定义注解,及自定义解析器实现对象自动注入操作
相关文章

 发表评论

暂时没有评论,来抢沙发吧~