【发布时间】:2015-12-07 12:10:50
【问题描述】:
我一直在使用 spring data rest 没有任何问题,但现在我有一个要求,当用户对给定实体(即 DELETE /accounts/<id>)执行 DELETE 操作时,我需要在数据库上设置一个标志,将该实体标记为已删除但我确实想保持记录。
基本上这意味着我需要在数据库中执行 UPDATE 而不是 DELETE 操作。我没有找到任何方法来覆盖 delete(ID) 方法的弹簧行为。
一些代码:
@Entity
@Table(name = "account")
public class Account {
/*
Default value for this field is false but when a receive a
DELETE request for this entity i want to turn this flag
to false instead of deleting the record.
*/
@Column(name = "deleted")
private boolean deleted;
...
}
帐户存储库
@RepositoryRestResource
public interface AccountRepository extends JpaRepository<Account, Integer> {
}
有什么想法吗?
【问题讨论】:
标签: java spring rest spring-data spring-data-rest