【发布时间】:2017-11-30 06:42:39
【问题描述】:
我正在编写一个 Rest 服务(HTTP Get 端点),在下面的 uri 中执行以下操作
http://localhost:8080/customers/{customer_id}
- 获取在 uri 中传递的 customer_id 的详细信息
- 如果没有通过customer_id (http://localhost:8080/customers),获取所有客户的详细信息。
代码:
@RequestMapping(method = RequestMethod.GET, value = "customers/{customer_id}")
public List<Customer> getCustomers(
@PathVariable(name = "customer_id", required = false) final String customerId) {
LOGGER.debug("customer_id {} received for getCustomers request", customerId);
}
但是,使用上面的代码,对于第二种情况,控制流向 getCustomers()。
注意:我使用的是 Java8 和 spring-web 4.3.10 版本
非常感谢您对此提供的任何帮助。
【问题讨论】:
标签: rest spring-mvc java-8 spring-restcontroller