Błażej Rejnowski
Błażej Rejnowski

Reputation: 259

Spring Angularjs - DELETE METHOD

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

Upvotes: 0

Views: 149

Answers (1)

Mustapha Belmokhtar
Mustapha Belmokhtar

Reputation: 1219

annotate your pack as the request body :

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

Upvotes: 1

Related Questions