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


@ApiOperation(value = "获取用户信息", notes = "userName:用户名{必传},  password:密码{必传} \n")
@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();
    }


}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM