In a URI, https://www.google.com/items/2 how to get 2 alone (item id) to process further
Asked
Active
Viewed 56 times
0
-
is this URI a part of the request? – Ankit Sharma Oct 05 '22 at 04:44
1 Answers
-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