Spring MVC: how to indicate whether a path variable is required or not?

VTTom`s solution is right, just change “value” variable to array and list all url possibilities: value={“https://stackoverflow.com/”, “/{id}”}

@RequestMapping(method=GET, value={"https://stackoverflow.com/", "/{id}"})
public void get(@PathVariable Optional<Integer> id) {
  if (id.isPresent()) {
    id.get()   //returns the id
  }
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)