Swagger2快速上手使用

Swagger2

快速入手

搭建

搭建springboot项目,略

  • 导入swagger所需依赖

    		<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger2</artifactId>
                <version>2.9.2</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger-ui</artifactId>
                <version>2.9.2</version>
            </dependency>
    
  • controller代码

    @RestController
    public class MyController {
         
         
        // 需指定使用的请求方法
        @GetMapping("/hello")
        public String hello(String name){
         
         
            return name;
        }
    }
    
  • 启动器添加@EnableSwagger2

  • localhost:port/swagger-ui.html

结果展示

在这里插入图片描述

方法接口参数调用

  1. 点击my-controller,点击Try it out

在这里插入图片描述

  1. 添加参数
    在这里插入图片描述

  2. 返回的值
    在这里插入图片描述

配置swagger

配置版本,文档信息

新建config类

@Configuration
public class SwaggerConfiguration {
   
   
    /**
     * Swagger的实例bean为docket,配置docket来配置Swagger具体参数
     *
     * @return
     */
    @Bean
    public Docket docket(){
   
   
                // 配置版本swagger2.0 可通过源码查询配置参数
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值