【发布时间】:2016-06-27 16:28:08
【问题描述】:
我不知道这是否可以直接实现(当然,还有其他更麻烦的方法可以做到这一点),但我希望能够在 Spring Boot 中通过其 URL 调用函数。
例如,假设我有一个@RestController,并且在那个休息控制器中,一个看起来像这样的函数:
@RequestMapping(value = "/", produces = "application/json", method = RequestMethod.POST)
public String myRequest(@RequestParam("request") String request) {
return request;
}
我想做的是让用户为我的 API 的不同端点传入一个相对 URL,我的代码将调用该部分的 api。例如:
// Pass in "/otherRequest/SomeInfo"
@RequestMapping(value = "/", produces = "application/json", method = RequestMethod.POST)
public String myRequest(@RequestParam("request") String request) {
//Goes to the function that handles "/otherRequest/SomeInfo"
// and returns its value
return callSomeFunctionByURL(request);
}
我意识到我可以解析字符串并通过一堆条件来获得我的结果,但是有没有更弹性的方式来做到这一点 - 比如通过调用callSomeFunctionByURL,或者会我只需要用旧方法吗? (对于那些想知道为什么会发生这种情况的人,这是一个理论问题)
【问题讨论】:
标签: java spring spring-boot rest