英文:
Rest Get: How to add "URL with Query Parameters" in Query Parameters of a URL?
问题
我有以下的要求:
/paymenturl?ordernr=123&amount=234&ourOwnCallbackUrl=$api/receipt?contractid=3232&callbackurl=https://somthing.com&fallbackurl=https:something.com&notification=hit-hard
- 是否可以将网址添加到查询参数中? (callbackUrl)
- 是否可以将步骤1添加到查询参数的值中? (ourOwnCallbackUrl)
- 是否可以将步骤1添加到步骤2中以形成主网址? (/paymenturl)
问题基本上是如何将另一个网址添加到查询参数中,以及是否可以进一步嵌套?
英文:
I have got requirements like below:
/paymenturl?ordernr=123&amount=234&ourOwnCallbackUrl=$api/receipt?contractid=3232&callbackurl=https://somthing.com&fallbackurl=https:something.com&notification=hit-hard
- Is it possible to add url in query parameter? (callbackUrl)
- Is it possible to add Step 1 into value of Query Parameter? (ourOwnCallbackUrl)
- Is it possible to add Step1 in Step 2 to main url? (/paymenturl)
The question is basically how to add another URL to query parameter and can it be nested further?
答案1
得分: 0
你必须转义特殊字符(如 &
)。我看到两种常见的方法:
-
使用百分比编码进行编码
%20%2Fpaymenturl%3Fordernr%3D123%26amount%3D234%26ourOwnCallbackUrl%3D%24api%2Freceipt%3Fcontractid%3D3232%26callbackurl%3Dhttps%3A%2F%2Fsomthing.com%26fallbackurl%3Dhttps%3Asomething.com%26notification%3Dhit-hard
-
或者您可以创建一个完整的数据传输对象(DTO),并使用请求正文与控制器之间进行发送/接收。
英文:
you have to escape the special characters (like &
) I see two common ways:
-
encode it in percent-encoded
%20%2Fpaymenturl%3Fordernr%3D123%26amount%3D234%26ourOwnCallbackUrl%3D%24api%2Freceipt%3Fcontractid%3D3232%26callbackurl%3Dhttps%3A%2F%2Fsomthing.com%26fallbackurl%3Dhttps%3Asomething.com%26notification%3Dhit-hard
-
or you can create a complete DTO (Data transfer object ) and use the request body to send/receive it from your controller.
专注分享java语言的经验与见解,让所有开发者获益!
评论