【发布时间】:2017-05-31 07:05:31
【问题描述】:
我想根据 userId 删除一条记录但是当我运行此代码并执行以下查询时,它给了我一个 404 错误 请帮助我如何删除数据?
PropertyReport.java
@Entity
@Table(uniqueConstraints={
@UniqueConstraint(columnNames = {"reportedProperty", "reporter"})
})
public class PropertyReport implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToOne (cascade = CascadeType.REMOVE, fetch = FetchType.EAGER, targetEntity = Property.class)
@JoinColumn(name="reportedProperty")
private Property property;
@OneToOne
@JoinColumn(name="reporter")
private User user;
@Column(length=1024)
private String Report;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Property getProperty() {
return property;
}
public void setProperty(Property property) {
this.property = property;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getReport() {
return Report;
}
public void setReport(String report) {
Report = report;
}
}
PropertyReportReppository.java
public interface PropertyReportRepository extends JpaRepository<PropertyReport, Long>{
@Modifying
@PreAuthorize("hasAuthority('allRights')")
@Query("delete from PropertyReport pr where pr.user.id=:userId")
int deleteTenantReview(@Param ("userId") Long userId); }
我调用的 API
API : http://localhost:8555/api/propertyReports/search/removeByUserId/2
【问题讨论】:
-
显示你的控制器层代码。
-
控制器层? @转发
-
为什么是 404?我认为这不是关于 db,而是关于 url 映射。
-
404 错误与 JPA 无关。这是来自您的网络服务器的错误,表明您尝试访问的 URL 未映射到任何资源。
-
我也不知道为什么 404 这就是我问的原因