Reputation:
I am working on rest api. I got error while delete data by id. All code is complete but don't know why postman fire error. I can map two table with unidirectional mapping using hibernate.
Here down is error in postman:
"message": "Required request body is missing: public org.springframework.http.ResponseEntity<org.springframework.http.HttpStatus> com.rest.RestApiPojo.Controller.PojoController.deleteAddressPerson(com.rest.RestApiPojo.Entity.Person,java.lang.Integer)"
Here down is my code:
Entity
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer person_id;
private String name;
@JsonManagedReference
@OneToOne(cascade = CascadeType.ALL, mappedBy = "person")
private Address address;
// getter setter
}
@Table(name = "address_master")
public class Address {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer address_id;
private String city;
private String country;
@JsonBackReference
@OneToOne(cascade=CascadeType.ALL, targetEntity = Person.class)
@JoinColumn(name = "person_id")
private Person person;
// getter setter
}
SeviceImpl
@Override
public void deleteAddressPerson(Integer personId) {
personRepo.deleteById(personId);
}
Controller
@RequestMapping(value = "/dltpersonaddress/{personId}", method = RequestMethod.DELETE)
public ResponseEntity<HttpStatus> deleteAddressPerson(@RequestBody Person person, @PathVariable Integer personId)
{
pojoService.deleteAddressPerson(personId);
return new ResponseEntity<>(HttpStatus.OK);
}
Upvotes: 1
Views: 480
Reputation: 25936
You have an unused @RequestBody Person person
parameter in your controller method.
@RequestMapping(value = "/dltpersonaddress/{personId}", method = RequestMethod.DELETE)
public ResponseEntity<HttpStatus> deleteAddressPerson(@RequestBody Person person, @PathVariable Integer personId)
{
pojoService.deleteAddressPerson(personId);
return new ResponseEntity<>(HttpStatus.OK);
}
The error message explains that this param is obligatory, and requests without it wont be processed.
Remove the param to solve the issue.
Upvotes: 2