Return 来自 spring 带有查询参数的 rest 控制器的响应
Return response from spring rest controller with query parameters
我想发送带有 redirectUri 和查询参数的 302 响应。我可以填写位置,但不确定如何将值作为查询参数包含在控制器的响应中。
我已尝试向主体添加值,但我想在查询参数中发送它们。
public ResponseEntity<Void> redirect(@RequestBody MultiValueMap<String,String> formVars, HttpServletResponse response) {
String clientId = formVars.getFirst(CLIENT_ID);
String redirectUri = formVars.getFirst(REDIRECT_URI);
String redirectToken = formVars.getFirst(REDIRECTION_TOKEN);
ResponseHandler<RedirectDto> redirectDtoResponseHandler = redirectService.redeemRedirectToken(redirectToken);
if (!redirectDtoResponseHandler.isPresent()) {
//handle error
}
redirectDtoResponseHandler.map(redirectDto -> toCookie(redirectDto.getCustomerSessionId()))
.ifPresent(response::addCookie);
URI uri = UriComponentsBuilder.fromHttpUrl(redirectUri).build().toUri();
//I'd like to add clientId as query param in this response?
return ResponseEntity.status(HttpStatus.FOUND).location(uri).build();
}
我想在此响应中添加 clientId 作为查询参数吗?
UriComponents uriComponents = UriComponentsBuilder.newInstance()
.scheme("http").host(redirectUri)
.path("/").query("clientId={keyword}").buildAndExpand(clientId);
我想发送带有 redirectUri 和查询参数的 302 响应。我可以填写位置,但不确定如何将值作为查询参数包含在控制器的响应中。
我已尝试向主体添加值,但我想在查询参数中发送它们。
public ResponseEntity<Void> redirect(@RequestBody MultiValueMap<String,String> formVars, HttpServletResponse response) {
String clientId = formVars.getFirst(CLIENT_ID);
String redirectUri = formVars.getFirst(REDIRECT_URI);
String redirectToken = formVars.getFirst(REDIRECTION_TOKEN);
ResponseHandler<RedirectDto> redirectDtoResponseHandler = redirectService.redeemRedirectToken(redirectToken);
if (!redirectDtoResponseHandler.isPresent()) {
//handle error
}
redirectDtoResponseHandler.map(redirectDto -> toCookie(redirectDto.getCustomerSessionId()))
.ifPresent(response::addCookie);
URI uri = UriComponentsBuilder.fromHttpUrl(redirectUri).build().toUri();
//I'd like to add clientId as query param in this response?
return ResponseEntity.status(HttpStatus.FOUND).location(uri).build();
}
我想在此响应中添加 clientId 作为查询参数吗?
UriComponents uriComponents = UriComponentsBuilder.newInstance()
.scheme("http").host(redirectUri)
.path("/").query("clientId={keyword}").buildAndExpand(clientId);