避免将spring数据中的数据保存在handleBeforeSave中 [英] Avoid saving data in spring data rest in handleBeforeSave
本文介绍了避免将spring数据中的数据保存在handleBeforeSave中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将 @RepositoryRestResource
用于 Mongo 存储库.我想做一些保存前的检查,如果这些检查不符合要求,我想放弃保存操作.
I am using @RepositoryRestResource
for Mongo Repositories.
I want to do some pre-save check and if those checks are not meeting the requirements, I want to abandon the save operation.
我试过了:
@HandleBeforeSave
public void handleBeforeSave(CallLog callLog)
throws InternalServerException {
CallLog log = callRepository.findOne(callLog.getConferenceId());
if (log != null
&& (callLog.getStatus().equals(Constants.CALL_IN_PROGRESS) || callLog
.getStatus().equals(Constants.CALL_DROPPED))) {
if (callLog.getStatus().equals(Constants.CALL_DROPPED)) {
User user = userRepository.findOne(callLog.getReceiverId());
user.setStatus(Constants.USER_STATUS_IDLE);
userRepository.save(user);
}
throw new InternalServerException(
"This call has already been received");
} else {
User user = userRepository.findOne(callLog.getReceiverId());
user.setStatus(Constants.USER_STATUS_BUSY);
userRepository.save(user);
}
}
但是抛出异常,实际上并没有放弃保存调用.还有其他方法吗?
But throwing exception, does not actually abandon the save call. Is there any other way to do it?
推荐答案
您可以使用 RestController 来拦截请求.
You can use a RestController to intercept the request.
这篇关于避免将spring数据中的数据保存在handleBeforeSave中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文