简体   繁体   中英

Spring optional rest endpoint path variable with multiple path variables

How can I have an optional path variable when I have multiple path variables?

This is not working: (organizationName is optional parameter)

  @GetMapping("/organizationreport/{month}/{year}/{organizationName}")
  public ResponseEntity<OrganizationReportJson> getOrganizationReport(
      @PathVariable("month") String month,
      @PathVariable("year") String year,
      @PathVariable Optional<String> organizationName) {

I get 404, wenn calling endpoint without organizationName

在路径变量中添加所需的属性,如下所示。

@PathVariable(required = false) String organizationName

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM