Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.

Commit 4d7c23e

Browse files
committed
デフォルト引数を用いる
1 parent 869cebb commit 4d7c23e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.ja.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,3 +431,31 @@ data class Foo(
431431
```
432432

433433
`KParameterAlias`で設定したエイリアスにもパラメータ名の変換が適用されます。
434+
435+
#### デフォルト引数を用いる
436+
`KRowMapper`では、特定の場面においてデフォルト引数を用いることができます。
437+
438+
##### 必ずデフォルト引数を用いる
439+
DBから取得した値を用いず、必ずデフォルト引数を用いたい場合、`KUseDefaultArgument`アノテーションを利用できます。
440+
441+
```kotlin
442+
class Foo(
443+
...,
444+
@KUseDefaultArgument
445+
val description: String = ""
446+
)
447+
```
448+
449+
`KRowMapper``ResultSet`に存在しないフィールドを取得しようとした場合、通常では例外で落ちますが、`KUseDefaultArgument`アノテーションを付与している場合取得処理そのものが行われません。
450+
これを応用することで、正常にマッピングを行うこともできます。
451+
452+
##### 取得結果がnullの場合デフォルト引数を用いる
453+
取得結果が`null`であればデフォルト引数を用いたいという場合、`KParameterRequireNonNull`アノテーションを利用できます。
454+
455+
```kotlin
456+
class Foo(
457+
...,
458+
@KParameterRequireNonNull
459+
val description: String = ""
460+
)
461+
```

0 commit comments

Comments
 (0)