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