@PathVariable仅当您要同时映射
GET /customers/{customer_id}和映射GETcustomers到单个java方法时才使用Optional 。
您不能发送的请求将被发送到
GET /customers/{customer_id}如果不发送customer_id。
因此,在您的情况下,它将是:
@RequestMapping(method = RequestMethod.GET, value = {"/customers", "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);}需要公共抽象布尔值
是否需要path变量。
默认为true,如果传入请求中缺少path变量,则会引发异常。如果您希望使用null或Java 8
java.util,请将其切换为false。例如在用于不同请求的ModelAttribute方法上。
您可以使用java8
null或
Optional从java8



