【发布时间】:2016-12-14 06:02:22
【问题描述】:
我有以下情况:
我的 REST API 之一:
@RestController
@RequestMapping("/controller1")
Public Class Controller1{
@RequestMapping(method = RequestMethod.POST)
public void process(@RequestBody String jsonString) throws InterruptedException, ExecutionException
{
............
}
}
用于 REST API(Controller1) 的 JSON POST 请求,request1:
{
"key1":"value1",
"key2":"value2"
}
我的 REST API 二:
@RestController
@RequestMapping("/controller2")
Public Class Controller2{
@RequestMapping(method = RequestMethod.POST)
public void process(@RequestBody String jsonString) throws InterruptedException, ExecutionException
{
............
}
}
用于 REST API(Controller2) 的 JSON 请求,request2:
{
"key1":"value1",
"key2":"value2",
"key3":"value3"
}
我有几个这样的“原始”请求。 现在,我期待一个 JSON 请求,我们称之为 request3,它是此类“原始”查询的组合——如下所示:
{
{
"requestType":"requestType1",
"request":"[{"key1":"value1","key2":"value2"}]"
},
{
"requestType":"requestType2",
"request":"[{"key1":"value1","key2":"value2","key3":"value3"}]"
}
}
在这里,我需要在识别查询类型时触发相应的 API(一个或两个)。我想知道如何将请求转发到相应的 REST API。我为 request3 编写了 REST API,如下所示:
@RestController
@RequestMapping("/controller3")
Public Class Controller3{
@RequestMapping(method = RequestMethod.POST)
public void process(@RequestBody String jsonString) throws InterruptedException, ExecutionException
{
..................
..................
switch(request){
case request1: //how to call REST API 1?
case request2: //how to call REST API 2?
}
}
}
【问题讨论】:
标签: json spring rest spring-boot request-mapping