You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 20, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+56Lines changed: 56 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -160,6 +160,62 @@ data class Dst(...) {
160
160
val mapper:KRowMapper<Dst> =KRowMapper(Dst::class)
161
161
```
162
162
163
+
### Conversion of argument names
164
+
By default, `KRowMapper` looks for the column corresponding to the argument name.
165
+
166
+
```kotlin
167
+
data classDst(
168
+
fooFoo:String,
169
+
barBar:String,
170
+
bazBaz:Int?
171
+
)
172
+
173
+
// required arguments: fooFoo, barBar, bazBaz
174
+
val mapper:KRowMapper<Dst> =KRowMapper(::Dst)
175
+
176
+
// the behavior is equivalent to the following
177
+
val rowMapper:RowMapper<Dst> = { rs, _ ->
178
+
Dst(
179
+
rs.getString("fooFoo"),
180
+
rs.getString("barBar"),
181
+
rs.getInt("bazBaz"),
182
+
)
183
+
}
184
+
```
185
+
186
+
On the other hand, if the argument naming convention is a `camelCase` and the DB column naming convention is a `snake_case` You will not be able to see the match in this case.
187
+
In this situation, you need to pass the naming transformation function at the initialization of `KRowMapper`.
188
+
189
+
```kotlin
190
+
val mapper:KRowMapper<Dst> =KRowMapper(::Dst) { fieldName:String->
191
+
/* some naming transformation process */
192
+
}
193
+
```
194
+
195
+
#### The actual conversion process
196
+
Since `KRowMapper` does not provide the naming transformation process, the naming transformation process requires an external library.
197
+
198
+
As an example, sample code that passes the conversion process from `camelCase` to `snake_case` is shown for two libraries, `Jackson` and `Guava`.
199
+
These libraries are often used by `Spring framework` and other libraries.
0 commit comments