swagger文档接口指定参数必传的方式

@ApiOperation(value = "获取用户信息", notes = "userName:用户名{必传},  password:密码{必传} 
")
@ApiImplicitParams({
            @ApiImplicitParam(name = "userName", value = "用户名", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "password", value = "密码", required = true, dataType = "String", paramType = "query")
    })

添加 required = true

来指定该参数必传

附swagger-ui的扫描配置

@Configuration  // 注册成ioc组件
@EnableSwagger2  //开启swagger2
public class SwaggerConfig {

    // 扫描所有带@ApiOperation注解的类
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .build();
    }


}
学习时的痛苦是暂时的 未学到的痛苦是终生的
本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/juanxincai/p/13385380.html