swagger使用GET方式传参时报错

如下代码使用GET请求方法时,groupGuid获取到的值为null
方法一、只需要将其改为Post方式请求即可,或者把paramType = “form” 换成 paramType = "query"就行

@ApiOperation(value = "获取组对象", notes = "get the group", httpMethod = "GET") //改为POST请求
@ApiImplicitParam(name = "groupGuid", value = "组ID", paramType = "form", dataType = "String", required = true)
@GetMapping(value="/get")//改为@PostMapping
public Group get(String groupGuid) {
	return groupService.get(groupGuid);
}

方法二、只使用@GetMapping(value="/get") ,将上面两行注解删掉也可

@GetMapping(value="/get") 
public Group get(String groupGuid) {
	return groupService.get(groupGuid);
}
可能是SSL证书问题导致的。你可以尝试在Swagger的配置文件中添加如下配置,忽略SSL证书的验证: ```java @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .protocols(new HashSet<>(Arrays.asList("https", "http"))) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.any()) .build() .securitySchemes(Arrays.asList(apiKey())) .securityContexts(Arrays.asList(securityContext())); } private ApiKey apiKey() { return new ApiKey("JWT", AUTHORIZATION_HEADER, "header"); } private SecurityContext securityContext() { return SecurityContext.builder() .securityReferences(defaultAuth()) .forPaths(PathSelectors.any()) .build(); } List<SecurityReference> defaultAuth() { AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; authorizationScopes[0] = authorizationScope; return Arrays.asList(new SecurityReference("JWT", authorizationScopes)); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("API接口文档") .description("SpringBoot整合Swagger,详细信息......") .termsOfServiceUrl("http://localhost:8080/") .contact("联系人") .version("1.0") .build(); } @Bean public RestTemplate restTemplate() throws Exception { TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true; SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build(); SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext); CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(csf).build(); HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(); requestFactory.setHttpClient(httpClient); RestTemplate restTemplate = new RestTemplate(requestFactory); return restTemplate; } ``` 其中,`restTemplate()` 方法中的代码是忽略SSL证书的验证。如果你不需要使用RestTemplate,可以不需要这个方法。
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值