Java 我使用Postman将数据传递给restapi,但我的变量显示空值
我的主要问题是如何将Map、String传递给restapi,我知道如果我使用@RequestBody,所有传递的内容都存储到Map中,但是如何传递Map以及restapi的任何其他参数Java 我使用Postman将数据传递给restapi,但我的变量显示空值,java,spring,api,rest,Java,Spring,Api,Rest,我的主要问题是如何将Map、String传递给restapi,我知道如果我使用@RequestBody,所有传递的内容都存储到Map中,但是如何传递Map以及restapi的任何其他参数 @GetMapping(path="/invoices") public String invoiceReceived( Map<String,Object> invoice,String format) throws MessagingException { System.out.
@GetMapping(path="/invoices")
public String invoiceReceived( Map<String,Object> invoice,String format) throws MessagingException {
System.out.println(format); // this prints NULL
return "returnValue";
}
这个问题与另一个问题类似,所以我试图解释这有什么不同,我知道我可以使用@RequestBody获取映射中的所有变量,但调用将使用两个参数,其中一些参数将存储在映射中,但一个参数将用于另一个变量。那么,如何将映射与任何其他变量一起发送呢?我认为您可以使用查询字符串和路径变量。 如果声明控制器的方法,如:
@GetMapping(path="/invoices")
public String invoiceReceived(@RequestBody Map<String,Object> invoice, @RequestParam String format) {
...
}
JSON请求主体:
{
"invoiceId":"23642",
"clientName":"Client",
"amount":"23742.67",
"email":"client@abc.com"
}
还可以使用路径变量,如:
http://localhost:8080/invoices/html
http://localhost:8080/invoices?format=html
{
"invoiceId":"23642",
"clientName":"Client",
"amount":"23742.67",
"email":"client@abc.com"
}
http://localhost:8080/invoices/html
@GetMapping(path="/invoices/{format}“)
public String invoiceReceived(@RequestBody Map<String,Object> invoice, @PathVariable String format) {
...
}