![](/img/trans.png)
[英]Spring can't construct query params from complex object for rest template
[英]Spring Rest Template Url contains complex query
我想調用一個將URL作為查詢參數的Web服務。 這是查詢:
{PK} IN({{Select {o.name} from {Student! as o} where {o.name} IN ({{Select {s.pk}
from {School as s} where {s.code}="school"}})}})
我使用此編碼查詢
然后將編碼的查詢放在Web服務url中: http:// host?query = query_above_encoded 。
因此,當執行此操作時(使用resttemplate
調用Web服務):
ResponseEntity<Model> response = restTemplate.exchange(
url, HttpMethod.GET, request, Model.class);
我得到這個例外:
org.springframework.web.client.HttpServerErrorException:500 Erreur內部Servlet
但是,當我使用其他客戶端應用程序(如Postman)調用相同的URL時,會得到響應。
有人有什么想法嗎?
解決方案是在對URL進行編碼后使用URI JAVA對象:
ResponseEntity<Model> response = restTemplate.exchange(
new URI(encodedUrl), HttpMethod.GET, request, Model.class);
希望這對別人有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.