0

In a URI, https://www.google.com/items/2 how to get 2 alone (item id) to process further

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

1 Answers1

-1

PATH VARIABLE

Its called PATH VARIABLE, this is just different type of HTTP REQUEST to send parameters within API. In SpringBoot we can use PATH VARIABLE like this :

@RestController
@RequestMapping("car")
public class CarController {

    @Autowired
    CarService carservice;

    @GetMapping("{id}")
    public Car getCarById(@PathVariable long id) {

    return carService.findById(id)
  }
}

Then you can call your api like this and send car id in last url

localhost:8080/car/1

LunaLissa
  • 45
  • 3
  • OP did nowhere said he's using Spring MVC. Just basic Servlets as indicated by the question tags. And Spring MVC (REST) controllers are absolutely not Servlets. – BalusC Oct 05 '22 at 09:57