what to return from my controller?

hey guys. i have this controller:
@RestController
@RequestMapping("api/v1/")
public class MainController {
private final ItemService itemService;

public MainController(ItemService itemService) {
this.itemService = itemService;
}
@GetMapping()
@ResponseBody
public List<Item> getItems(@RequestParam("distance") double distance, @RequestParam("season") String season) {
System.out.println(distance);
System.out.println(season);

List<Item> listOfItems=itemService.getItemsByDistanceAndSeason(distance, season);

ResponseEntity<List<Item>> response = listOfItems;//err. required: ResponseEntity<List<Item>>, provided List<Item>
return response;
}
}
@RestController
@RequestMapping("api/v1/")
public class MainController {
private final ItemService itemService;

public MainController(ItemService itemService) {
this.itemService = itemService;
}
@GetMapping()
@ResponseBody
public List<Item> getItems(@RequestParam("distance") double distance, @RequestParam("season") String season) {
System.out.println(distance);
System.out.println(season);

List<Item> listOfItems=itemService.getItemsByDistanceAndSeason(distance, season);

ResponseEntity<List<Item>> response = listOfItems;//err. required: ResponseEntity<List<Item>>, provided List<Item>
return response;
}
}
and i dont understand how to return list of Items from my controller. can smb help me out?
11 Replies
JavaBot
JavaBot11mo 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.
tjoener
tjoener11mo ago
just return listOfItems done, code works
bambyzas
bambyzasOP11mo ago
ive seen people returning ResponseEntity. which to choose then?
tjoener
tjoener11mo ago
Don't do it It's for specific circumstances only Like specific status codes or headers
bambyzas
bambyzasOP11mo ago
i was told this. so now im completely lost
No description
tjoener
tjoener11mo ago
Like I said, you don't need it yet Once you get better at spring and api design you might need it
bambyzas
bambyzasOP11mo ago
wdym?
tjoener
tjoener11mo ago
Because when you understand this, then you need it Don't run before you can walk
bambyzas
bambyzasOP11mo ago
ok. thanks bro
JavaBot
JavaBot11mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
JavaBot
JavaBot11mo ago
Post Closed
This post has been closed by <@611623200756989972>.
Want results from more Discord servers?
Add your server