my controller cant accept query params

hey guys. can smb help me out? i dont understand what im doing wrong. i have this controller:
@RestController
@RequestMapping("api/v1/")
public class MainController {
private final ItemService itemService;

public MainController(ItemService itemService) {
this.itemService = itemService;
}

@GetMapping("{distance}")
@ResponseBody
public ResponseEntity<String> getItems(@RequestParam("distance") double distance) {
System.out.println("AAA");
System.out.println(distance);

itemService.getItemsByDistanceAndSeason(100,"winter");

return new ResponseEntity<String>("Hello World", HttpStatus.CREATED);
}
}
@RestController
@RequestMapping("api/v1/")
public class MainController {
private final ItemService itemService;

public MainController(ItemService itemService) {
this.itemService = itemService;
}

@GetMapping("{distance}")
@ResponseBody
public ResponseEntity<String> getItems(@RequestParam("distance") double distance) {
System.out.println("AAA");
System.out.println(distance);

itemService.getItemsByDistanceAndSeason(100,"winter");

return new ResponseEntity<String>("Hello World", HttpStatus.CREATED);
}
}
and i do GET localhost:8080/api/v1/?distance=100 but i get:
{
"timestamp": "2024-02-02T19:49:08.694+00:00",
"status": 404,
"error": "Not Found",
"trace": "org.springframework.web.servlet.resource.NoResourceFoundException: No static resource api/v1.\n\tat org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:585)\n\tat org.
{
"timestamp": "2024-02-02T19:49:08.694+00:00",
"status": 404,
"error": "Not Found",
"trace": "org.springframework.web.servlet.resource.NoResourceFoundException: No static resource api/v1.\n\tat org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:585)\n\tat org.
if remove query param from my code and just do GET to the /api/v1/ endpoint, everythings fine. can smb help me out? thx
3 Replies
JavaBot
JavaBot14mo ago
This post has been reserved for your question.
Hey @bambyzas! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Unknown User
Unknown User14mo ago
Message Not Public
Sign In & Join Server To View
JavaBot
JavaBot14mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?