Reputation: 171
I am new to Spring
and I am trying to do the basic GET
and POST
method.
This is how I am trying to do the methods:
@RestController
public class DeskController {
@Autowired
private DeskDao dao;
@GetMapping("desks")
public List<Desk> getDesks() {
System.out.println(dao.findById(1L));
return dao.findAll();
}
@PostMapping("desks")
public Desk save(@RequestBody @Valid Desk desk) {
Desk deskObj = dao.save(desk);
System.out.println(deskObj);
return deskObj;
}
When I am calling the POST
method like this I get the pring
with the actual object that I had called it with so it is working fine, but I also get this error:
javax.ws.rs.ProcessingException: Content-Type is missing
And when trying to call GET
it tells me that:
org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported
I am aware that I have not included the whole code, but I will add what is needed to resolve this error since there are a lot of classes.
My questions are, what do I do against the first error
and why is GET
method not supported?
Upvotes: 1
Views: 1169
Reputation: 15423
Two things you need to change :
/
to indicate that for this path you will perform an
operation. For eg : (/desks
)@Consumes
to
indicate that this method accepts the payload in particular format. For eg : @Consumes(MediaType.APPLICATION_JSON)
annotated over your save()
method.Upvotes: 1