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();
    }


}

 

posted @ 2020-07-27 14:48  卷心菜的奇妙历险  阅读(5341)  评论(1编辑  收藏  举报