zoukankan      html  css  js  c++  java
  • swagger-ui生成的文档有delete,get,head,options,patch

    自己学习swagger-ui时。发现生成的文档不太对。pom.xml 添加依赖

            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger2</artifactId>
                <version>2.5.0</version>
            </dependency>
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger-ui</artifactId>
                <version>2.5.0</version>
            </dependency>
    

      

    添加代码

    package com.example;
    
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    
    import springfox.documentation.builders.ApiInfoBuilder;
    import springfox.documentation.builders.PathSelectors;
    import springfox.documentation.builders.RequestHandlerSelectors;
    import springfox.documentation.service.ApiInfo;
    import springfox.documentation.spi.DocumentationType;
    import springfox.documentation.spring.web.plugins.Docket;
    import springfox.documentation.swagger2.annotations.EnableSwagger2;
    
    
    @Configuration
    @EnableSwagger2
    public class Swagger2 {
    
        @Bean
        public Docket createRestApi() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(apiInfo())
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("com.example.controller"))
                    .paths(PathSelectors.any())
                    .build();
        }
    
        private ApiInfo apiInfo() {
            return new ApiInfoBuilder()
                    .title("example REST API文档")
                    .description("--------------------------------")
                    .termsOfServiceUrl("https://i.cnblogs.com/")
                    .contact("zjf")
                    .version("0.1.1")
                    .build();
        }
    
    }
    

      

    controller

    package com.example.controller;
    
    
    import com.example.service.UserService;
    import io.swagger.annotations.Api;
    import io.swagger.annotations.ApiOperation;
    import io.swagger.annotations.ApiParam;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.*;
    
    @Api(value="用户controller",description="用户操作",tags={"用户操作接口"})
    @RestController
    @RequestMapping("/testBoot")
    public class UserController {
    
        @Autowired
        private UserService userService;
        @ApiOperation("获取用户信息")
        @RequestMapping("getUser/{id}")
        public String GetUser(@PathVariable int id){
            return userService.Sel(id).toString();
        }
    }
    

      打卡地址 http://localhost:8080/swagger-ui.html

    显示效果

    原因修改下controller 方法

    package com.example.controller;
    
    
    import com.example.service.UserService;
    import io.swagger.annotations.Api;
    import io.swagger.annotations.ApiOperation;
    import io.swagger.annotations.ApiParam;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.*;
    
    
    
    @Api(value="用户controller",description="用户操作",tags={"用户操作接口"})
    @RestController
    @RequestMapping("/testBoot")
    public class UserController {
    
        @Autowired
        private UserService userService;
        @ApiOperation("获取用户信息")
        @RequestMapping("getUser/{id}")
        public String GetUser(@PathVariable int id){
            return userService.Sel(id).toString();
        }
    
        @ApiOperation("获取表是否存在")
        @GetMapping("/getTable")
        public int getTable(@ApiParam(name = "tableName", value = "表名", required = true)@RequestParam String tableName){
            return userService.isTableExist(tableName);
        }
    }
    

      显示效果

  • 相关阅读:
    【HTML】添加网页背景音乐
    无线安全之破解WPA/WPA2 加密WiFi
    基于deepin-wine的windows软件打包deb安装包教程
    deepin V20 启用Nvidia驱动方法
    [Liunx]Linux安装screenfetch
    开往-友链接力
    linux常用命令(六)提权和文件上传下载的操作
    抓住会员!奇点云DataNuza重大发布
    喜讯 | 奇点云入选「GMIC 2020 PRO 十佳新生代」榜单
    数据智能应用最终实现企业降本增效
  • 原文地址:https://www.cnblogs.com/zjf6666/p/14782019.html
Copyright © 2011-2022 走看看