0

I have a problem with delete method. I try to delete a entity by Request Body.

Controller:

 @RequestMapping(value = "/remove", method = DELETE)
 public void remove(Package pack) {  
   packageRepository.delete(pack);   
}

And AngularJS:

    $http({
        method : 'DELETE',
        url : '/api/package/remove',
        data : pack

    }).then

Where pack is a Entity. What should i do ? All time i am getting message: Required request body is missing: public javax.xml.ws.Response com.controller.PackageController.remove(com.model.Package)

Class Package:

@Entity
@Data
@Table(name = "Package")
@NoArgsConstructor
@AllArgsConstructor
public class Package {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String name;

private String description;

private Double weight;

private Double xDimension;

private Double yDimension;

private Double zDimension;

private Double capacity;

private LocalDateTime whenTake;

private String timeString;


@OneToOne
private User user;

@OneToOne
private Warehouse warehouse;

@ManyToOne
@Null
@JsonIgnore
private Route route;
}

Json body:

 capacity: 20
 description: "Kolo jest okrągłe"
 id: 1
 name: "Koła Audi"
 timeString: "2017-11-24 18:43:23"
 user: {…}
   address: "Graniczna 25"
   email: null
   firmName: "Swinouscie Comapny"
   firstName: "Karol"
   id: 1
   lastName: "Cichowski"
   telephoneNumber: "700880774"
 warehouse: {…}
   address: "Sportowa 16"
   id: 1
   name: "Magazyn Amazon"
   telephoneNumber: "74-816-342-465"
weight: 29
whenTake: null
xDimension: null
yDimension: null
zDimension: null
7
  • Can it be that the body is just ignored? stackoverflow.com/questions/299628/… Commented Nov 24, 2017 at 17:30
  • Please post the relevant code of Package class and pack in angularjs Commented Nov 24, 2017 at 17:31
  • maybe but what other i should send? only id ? I try with @PathVariable and still this same error Commented Nov 24, 2017 at 17:32
  • by using F12 in Firefox i see a pack's Json body and is correct. I try with headers = "content-type=application/x-www-form-urlencoded" but its dosnt work Commented Nov 24, 2017 at 17:36
  • I think it's more common to just pass the id on a DELETE, which could be added as querystring parameter. Commented Nov 24, 2017 at 17:40

1 Answer 1

1

annotate your pack as the request body :

@RequestMapping(value = "/remove", method = DELETE)
  public void remove(@RequestBody Package pack) {  
  packageRepository.delete(pack);   
   }
Sign up to request clarification or add additional context in comments.

4 Comments

instead of void put Packageas your return type, and inside your method after deleting the pack return pack;
i got 200 -> by F12 i see a body paramteres which i send and output (answer) -> all package paramteres are nulls. But when i refresh page and when i try to get all exist elements still i see this same element whose i deleted ;/ I see table in h2 and this element is still there.
@MikeEvans then you're hitting the controller but now your problem is with persistence?
With persistence? Can you explain?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.