当前位置:网站首页 > R语言数据分析 > 正文

swagger2配置(swagger2配置登录)

您好,以下是

springboot 整合 swagger

2的步骤

demo

1. 在pom.xml文件添加

swagger

2的依赖:

 <dependency> <groupId>io. spring fox</groupId> <artifactId> spring fox- swagger 2</artifactId> <version>2.9.2</version> </dependency> 

2. 创建

Swagger

2

配置

类,用于

配置 Swagger

2相关信息:

 @Configuration @Enable Swagger 2 public class Swagger 2Config { @Bean public Docket createRestApi() { return new Docket(DocumentationType. SWAGGER _2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.example. demo .controller")) .paths(PathSelectors.any()) .build(); }  private ApiInfo apiInfo() { return new ApiInfoBuilder() .title(" Spring Boot 中使用 Swagger 2构建RESTful APIs") .description("更多 Spring Boot 相关文章请关注:http://www.example.com/") .termsOfServiceUrl("http://www.example.com/") .contact("example") .version("1.0") .build(); } } 

3. 在Controller类中添加

Swagger

2注解,用于描述接口信息:

 @RestController @RequestMapping("/user") @Api(tags = "用户管理") public class UserController { @ApiOperation(value = "获取用户列表", notes = "获取所有用户列表") @GetMapping("/list") public List<User> list() { // ... }  @ApiOperation(value = "创建用户", notes = "根据User对象创建用户") @ApiImplicitParam(name = "user", value = "用户实体", required = true, dataType = "User") @PostMapping("/create") public String create(@RequestBody User user) { // ... }  @ApiOperation(value = "更新用户", notes = "根据User对象更新用户") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long"), @ApiImplicitParam(name = "user", value = "用户实体", required = true, dataType = "User") }) @PutMapping("/update/{id}") public String update(@PathVariable Long id, @RequestBody User user) { // ... }  @ApiOperation(value = "删除用户", notes = "根据ID删除用户") @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long") @DeleteMapping("/delete/{id}") public String delete(@PathVariable Long id) { // ... } } 

4. 启动应用程序,访问http://localhost:8080/

swagger

-ui.html,即可查看

Swagger

2生成的接口文档。

希望对您有所帮助!

到此这篇swagger2配置(swagger2配置登录)的文章就介绍到这了,更多相关内容请继续浏览下面的相关推荐文章,希望大家都能在编程的领域有一番成就!

版权声明


相关文章:

  • arcpy模块(Arcpy模块的特点)2025-01-16 16:27:10
  • top18女rapper(top18女rapperSex)2025-01-16 16:27:10
  • store苹果商店下载(store苹果商店下载不了软件)2025-01-16 16:27:10
  • rk3288开机启动app(开机启动app下载)2025-01-16 16:27:10
  • spring视频课程(springship)2025-01-16 16:27:10
  • orcale默认用户(oracle 用户默认表空间)2025-01-16 16:27:10
  • nfs文件服务器(nfs server用到的文件和目录)2025-01-16 16:27:10
  • chronyc -a makestep不生效(chronyc -a makestep不生效 etc权限)2025-01-16 16:27:10
  • mha-al00是华为手机的什么型号(art-al00m华为什么型号手机)2025-01-16 16:27:10
  • Rknn3588开机自动启动qt(Rknn3588开机自动启动qt)2025-01-16 16:27:10
  • 全屏图片