๐Ÿ”™๋’ค๋กœ๊ฐ€๊ธฐ

1. val vs var ๊ฐœ๋…

  1. val
  2. var

2. ModelMapper์—์„œ์˜ ๋ฌธ์ œ

2.1 ModelMapper์˜ ๊ธฐ๋ณธ ๋™์ž‘ ์›๋ฆฌ

2.2 val๋งŒ ์žˆ๋Š” ํด๋ž˜์Šค ๋งคํ•‘ ์‹œ ๋ฌธ์ œ


3. ์˜ˆ์‹œ ์ฝ”๋“œ

3.1 ๋ฌธ์ œ ์˜ˆ์‹œ

// โ˜… ๋ฌธ์ œ ์˜ˆ์‹œ: val๋งŒ ์‚ฌ์šฉํ•œ DTO
open class LectureValDto {
    val id: String? = null
    val title: String? = null
    val content: String? = null
}

// ModelMapper ๋งคํ•‘ ์ฝ”๋“œ (๊ฐ„๋‹จ ์˜ˆ์‹œ)
// ์—ฌ๊ธฐ์„  LectureEntity -> LectureValDto ๋ณ€ํ™˜์„ ์‹œ๋„ํ•œ๋‹ค๊ณ  ๊ฐ€์ •
val modelMapper = ModelMapper()
val entity = LectureEntity("L001", "Kotlin ๊ฐ•์˜", "val/var ์ฐจ์ด ์„ค๋ช…")
val dto: LectureValDto = modelMapper.map(entity, LectureValDto::class.java)

// dto ๋‚ด๋ถ€ ํ•„๋“œ๊ฐ€ ์ „๋ถ€ null ์ƒํƒœ๋กœ ๋‚จ์Œ
println(dto.id)      // null
println(dto.title)   // null
println(dto.content) // null