我想通過添加附加列 delete=true 而不是從資料庫中洗掉真實用戶來進行軟洗掉。我有以下方法UserServiceImpl:
@Override
public void deleteUser(String id) {
UserEntity userEntity = userRepository.findById(Integer.valueOf(id))
.orElseThrow(() -> new UserNotFoundException("Id not found"));
if (userEntity.getLastAccessDate() == null) {
throw new ProhibitedScimTypeException("Broken policy");
}
userRepository.delete(userEntity);
}
在UserController我有:
@ApiResponses(value = {
@ApiResponse(responseCode = "204", content = {@Content(schema = @Schema(implementation = UserResource.class))}, description = "Successful")
})
@DeleteMapping("/Users/{id}")
public ResponseEntity<String> deleteUser(@PathVariable("id") String id) {
userService.deleteUser(id);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
在UserRepository我添加了以下方法:
@Query("update UserEntity u set deleted = true where u = :u")
void delete(UserEntity userEntity);
如果在存盤庫中沒有此方法,它不會設定為真,deleted但使用void delete我會發現錯誤Using named parameters for method not found in annotated query 'update user set deleted = true where user = :user'。你能給我一些建議嗎 - 軟洗掉的正確方法是什么?
uj5u.com熱心網友回復:
您對引數userEntity的參考@Query不正確。它應該是:
@Query("update UserEntity u set deleted = true where u = :userEntity")
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/533625.html
標籤:爪哇休息http-删除
