Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 构建一个rest包装器,它接受任何类型的请求_Java_Rest_Spring Boot_Spring Mvc_Jersey - Fatal编程技术网

Java 构建一个rest包装器,它接受任何类型的请求

Java 构建一个rest包装器,它接受任何类型的请求,java,rest,spring-boot,spring-mvc,jersey,Java,Rest,Spring Boot,Spring Mvc,Jersey,我想在spring引导应用程序中构建一个rest包装器,它接受任何类型的请求(API调用)。假设我有两个API调用/employee/123(GET方法)/dept/123(PUT方法)。现在,当我点击来自postman客户端的这两个请求时,我的包装器应该接受这两种类型的请求 我用过滤器和拦截器试过了。但这些对我来说不起作用。谁能解释一下怎么做 不太清楚你有什么问题。这就是你要找的吗 @RestController public class SampleController { @Ge

我想在spring引导应用程序中构建一个rest包装器,它接受任何类型的请求(API调用)。假设我有两个API调用/employee/123(GET方法)/dept/123(PUT方法)。现在,当我点击来自postman客户端的这两个请求时,我的包装器应该接受这两种类型的请求


我用过滤器和拦截器试过了。但这些对我来说不起作用。谁能解释一下怎么做

不太清楚你有什么问题。这就是你要找的吗

@RestController
public class SampleController {

    @GetMapping(path = "/employee/{id}")
    public String getEmployee(@PathVariable int id) {
       ....
    }

    @PutMapping(path = "/dept/{id}")
    public String putDept(@PathVariable int id) {
       ....
    }
}

或者你想要一个API代理?所以,也许,看看Zuul或任何类似的项目是有意义的?

如果你想接受任何类型的请求,比如POST,GET,在
@RequestMapping
中删除或放置不提及
RequestMethod
的方法,如果您想根据请求方法执行不同的操作,请使用
HttpServletRequest
获取ReuestMethod 例如


谢谢你,卡米。我正在寻找一个API代理。正如你提到的,我会和祖尔一起试试。谢谢。我看起来也一样。我试试这个。
@RequestMapping({ "/employee/{id}", "/dept/{id}" })
    public @ResponseBody String demo(HttpServletRequest request, @PathVariable("id") Integer id) {

        if (request.getMethod().equalsIgnoreCase("POST")) {
            return "POST MEhod";
        } else if (request.getMethod().equalsIgnoreCase("GET")) {
            return "GET Method";
        } else if (request.getMethod().equalsIgnoreCase("PUT")) {
            return "PUT Method";
        } else {
            return "DELETE Method";
        }

    }