π₯ MyBatis camelCase μ²λ¦¬
π₯ MyBatis camelCase μ²λ¦¬
λ¬Έμ μν©
- μ½λμ
Query
λͺ¨λ λΆλͺ μ λλ‘ μμ±λμ΄ μλλ° λ±λ‘μμ μμ μΌμμ μλͺ»λ κ°μ΄ λ§€ν λμλ€. Query
μ λν μλ΅DTO
λ₯ΌLogging
ν΄ λ³΄λ λ€μκ³Ό κ°μλ€.
1
2
3
4
5
6
7
8
9
10
[
NoticeResponseDto(
writerEmail='μ λͺ©'
, writerName='λ΄μ©'
, title='μ λͺ©'
, content=λ΄μ©
, createdDate='2025-03-18'
, updatedDate='κΉμ§ν'
)
]
λ¬Έμ μμΈ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
@Schema(description = "곡μ§μ¬ν λͺ©λ‘ μ‘°ν μλ΅ DTO")
class NoticeResponseDto (
@Schema(description = "μμ±μ μ΄λ©μΌ")
val writerEmail: String,
@Schema(description = "μμ±μ μ΄λ¦")
val writerName: String,
@Schema(description = "μ λͺ©")
val title: String,
@Schema(description = "λ΄μ©")
val content: String,
@Schema(description = "λ±λ‘μΌμ")
val createdDate: String,
@Schema(description = "μμ μΌμ")
val updatedDate: String
)
MyBatis
λ κΈ°λ³Έμ μΌλ‘ λ§€ν μsnake_case
βcamelCase
μλ λ§€νμ μ§μνμ§ μκΈ° λλ¬Έμ, μΌμΉνμ§ μμ κ²½μ°resultMap
μ λ°λ‘ μ§μ ν΄μΌ νλ€.
ν΄κ²° λ°©λ²
β μμ±μ κΈ°λ° λ§€ν
1
2
3
4
5
6
7
8
9
10
<resultMap id="NoticeResponseMap" type="com.example.dto.NoticeResponseDto">
<constructor>
<arg column="writer_email" javaType="String"/>
<arg column="writer_name" javaType="String"/>
<arg column="title" javaType="String"/>
<arg column="content" javaType="String"/>
<arg column="created_date" javaType="String"/>
<arg column="updated_date" javaType="String"/>
</constructor>
</resultMap>
- μμ±μ νλΌλ―Έν° μμκ°
<constructor>
μ<arg>
μμμ λ°λμ μΌμΉν΄μΌ νλ€.
β
application.properties
μλ λ§€ν μ€μ
1
mybatis.configuration.map-underscore-to-camel-case=true
MyBatis
λ μμ κ°μ΄camelCase
μ€μ μ ν΄μ£Όμ΄μΌ νλ€κ³ νλ€.- μ΄ λ°©λ²μ λͺ¨λ νλμ
@Setter
κ° μ€μ λμ΄ μμ΄μΌ νλ€.
νκ³
- ν΄κ²° λ°©λ²μ κ°λ¨νμ§λ§, μ»΄νμΌμ΄λ μμΈκ° ν°μ§μ§ μλ λ¬Έμ κ° μ€νλ € λ ν΄κ²°νκΈ° μ΄λ €μ΄ κ² κ°λ€.
This post is licensed under CC BY 4.0 by the author.