質問するログイン新規登録

回答編集履歴

1

追記

2021/10/14 14:06

投稿

IT001
IT001

スコア675

answer CHANGED
@@ -9,4 +9,16 @@
9
9
  customerRepository.deleteById(id);
10
10
  ```
11
11
 
12
- [参考: Spring公式のissue](https://github.com/spring-projects/spring-data-commons/issues/1399)
12
+ [参考: Spring公式のissue](https://github.com/spring-projects/spring-data-commons/issues/1399)
13
+
14
+ ---
15
+ ■追記
16
+
17
+ Optionalは、色々書き方がありますが、例えば以下のようなことができます。
18
+
19
+ ```java
20
+ public Customer findOne(Integer id) {
21
+ return customerRepository.findById(id).orElseThrow(() ->
22
+ new EntityNotFoundException("Customer not found with id " + id));
23
+ }
24
+ ```