I'm new to SpringBoot and I'm creating the "basic project" to understand it, a CRUD project. I have a "Service Class" that implements a "Repository Interface":
As you can see, in my Service Class I'm returning a List of students, which I'll use in my "Controller Class":
What I realize is that I cant send a List of students and receive the List in my Controller class. I triend with @RequestBody but then I read that @RequestBody can't be used with @GetMapping. So is there a form to pass my List from my Service Class to my Controller class? is there an annotation to do that? Am I using wrong @RequesBody? Thank you so much for helping me.
CodePudding user response:
An HTTP GET request cannot have a body, you can use multiple RequestParam values but you cannot have a body. If you want a body you can use a POST request instead.
You don't need to pass values with requests within your application, you can just call the method of SService within the controller. You should clarify what exactly you want it to do.
CodePudding user response:
Use @RestController
instead of @Controller
.
@RestController annotation is a special controller used in RESTful Web services, and it’s the combination of @Controller and @ResponseBody annotation.
And you can call your service method with the service Object that you have already Autowired it.