gpt4 book ai didi

java - Spring Angularjs - 删除方法

转载 作者:行者123 更新时间:2023-12-02 11:57:37 25 4
gpt4 key购买 nike

我的删除方法有问题。我尝试通过请求正文删除实体。

Controller :

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

还有 AngularJS:

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

}).then

其中 pack 是一个实体。我应该怎么办 ?我一直收到消息:缺少必需的请求正文:public javax.xml.ws.Response com.controller.PackageController.remove(com.model.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 正文:

 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

最佳答案

将您的包注释为请求正文:

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

关于java - Spring Angularjs - 删除方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47477785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com