将所有端点置于同一路径中并在 header 内声明结束路径
Have all endpoints in same path and declared ending path inside header
我有一个端点适用于所有应用程序,例如 https://localhost:8080/test,在 header 内部,我有参数和 URL 的其余部分。您知道如何在 java/spring proyect 中实现这项工作吗?
您可以使用 @RequestMapping 的 headers 参数将您的请求映射到特定的 header .
@RestController
@RequestMapping(path = "/test")
public class TestController {
@RequestMapping(headers = "X-TEST=1")
public void path1() {
// Called when header "X-TEST" present and with 1
}
@RequestMapping(headers = "X-TEST=2")
public void path2() {
// Called when header "X-TEST" present and with 2
}
// ...
}
我有一个端点适用于所有应用程序,例如 https://localhost:8080/test,在 header 内部,我有参数和 URL 的其余部分。您知道如何在 java/spring proyect 中实现这项工作吗?
您可以使用 @RequestMapping 的 headers 参数将您的请求映射到特定的 header .
@RestController
@RequestMapping(path = "/test")
public class TestController {
@RequestMapping(headers = "X-TEST=1")
public void path1() {
// Called when header "X-TEST" present and with 1
}
@RequestMapping(headers = "X-TEST=2")
public void path2() {
// Called when header "X-TEST" present and with 2
}
// ...
}