Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot @在双向关系中,我该如何@DeleteMapping?_Spring Boot_Jpa - Fatal编程技术网

Spring boot @在双向关系中,我该如何@DeleteMapping?

Spring boot @在双向关系中,我该如何@DeleteMapping?,spring-boot,jpa,Spring Boot,Jpa,我想以1:N关系从父对象中删除子对象。 下面是我写的代码 springboot(JPA) @OneToMany(mappedBy=“user”,fetch=FetchType.EAGER,orphandremovation=true) @JsonManagedReference private Set productInfos=new HashSet(); @许多酮 @JoinColumn(name=“username”,referencedColumnName=“username”) @Jso

我想以1:N关系从父对象中删除子对象。 下面是我写的代码

springboot(JPA)

@OneToMany(mappedBy=“user”,fetch=FetchType.EAGER,orphandremovation=true)
@JsonManagedReference
private Set productInfos=new HashSet();
@许多酮
@JoinColumn(name=“username”,referencedColumnName=“username”)
@JsonBackReference
私人用户;
springboot(控制器)

@DeleteMapping(“/productSetting/{id}”)
公共响应属性deleteUserProduct(@PathVariable(“id”)长id){
试一试{
User=userRepository.findById(id).get();
deleteAll(user.getProductInfo());
System.out.println(“>>>>>>>>”);
返回新的响应属性(HttpStatus.NO_内容);
}捕获(例外e){
返回新的响应属性(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
这个代码有效。但是,我想获取产品的id并仅删除选定的id。有办法吗

@OneToMany(mappedBy = "user", fetch = FetchType.EAGER, orphanRemoval = true)
@JsonManagedReference
private Set<ProductInfo> productInfos = new HashSet<>();

@ManyToOne
@JoinColumn(name = "username", referencedColumnName = "username")
@JsonBackReference
private User user;
@DeleteMapping("/productSetting/{id}")
public ResponseEntity<HttpStatus> deleteUserProduct(@PathVariable("id") long id) {
    try {
        User user = userRepository.findById(id).get();
        productInfoRepository.deleteAll(user.getProductInfo());
        System.out.println(">>>>>>>>>>>>>>");
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    } catch (Exception e) {
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    }
}