๐ฅ 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.