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
JavaBot13mo 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
tjoener13mo ago
just return listOfItems done, code works
i hate SQL so much its unreal
ive seen people returning ResponseEntity. which to choose then?
tjoener
tjoener13mo ago
Don't do it It's for specific circumstances only Like specific status codes or headers
i hate SQL so much its unreal
i was told this. so now im completely lost
No description
tjoener
tjoener13mo ago
Like I said, you don't need it yet Once you get better at spring and api design you might need it
tjoener
tjoener13mo ago
Because when you understand this, then you need it Don't run before you can walk
i hate SQL so much its unreal
ok. thanks bro
JavaBot
JavaBot13mo 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
JavaBot13mo ago
Post Closed
This post has been closed by <@611623200756989972>.

Did you find this page helpful?