Spring-fox整合SpringBoot步骤

1.spring-fox依赖

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>

2.springBoot启动类上方添加注解(@EnableSwagger2,@EnableWebMvc)

@SpringBootApplication
@EnableSwagger2 //swagger2注解
@EnableWebMvc 
public class SwaggerDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(SwaggerDemoApplication.class, args);
    }

}

3.常用注解

        @api:

        作用于控制层controller类上方,对controller说明

        @apiOperation:

         作用于url方法上,对方法进行说明

        @ApiParam:

        作用于参数前,对参数进行说明

@Controller
@Api(tags = {"swaggerController"},description = "描述") ///@Api作用于controller类上方
public class SwaggerController {

    @GetMapping(value = {"/getpeople"})
    @ResponseBody
    @ApiOperation(value = "方法描述") /// @ApiOperation作用于方法上方
    public String test2(@ApiParam(value = "学号ID",// @ApiParam作用于参数上
            required = false) Integer id, String name){
        System.out.println("swagger测试");
        System.out.println(id+"----"+name);
        return "Swagger测试";
    }
    
}

        @ApiModel:

         作用于实体类上方

        @ApiModelProperty:

        作用于属性上方

@ApiModel(value = "people实体类")///@ApiModel作用于实体类上方
public class People {
    private Integer id;
    @ApiModelProperty(value = "姓名")///@ApiModelProperty作用于属性上方说明
    private String name;
    private String address;
}

   博客:孤独&烙印的博客_CSDN博客-springSecurity,spring-fox,vue领域博主

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孤独&烙印

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值