spring-boot

๊ต์œก๊ณผ์ • ๋™์•ˆ ์–ธ์ œ ๋งŒ๋“ค์–ด์กŒ๋Š”์ง€, ์–ธ์ œ ์ˆ˜์ •๋˜์—ˆ๋Š”์ง€์— ๋”ฐ๋ฅธ ์œ ์ง€๋ณด์ˆ˜ ์ค‘์š”์„ฑ์„ ๋ฐฐ์šฐ์ง„ ๋ชปํ–ˆ๋‹ค. ์ด์ œ ๋ชจ๋ธ๋งํ•  ๋•Œ ๊ณ ๋ คํ•ด์„œ ์งœ์•ผ๊ฒ ๊ตฐ... ๊ฐ™์€ ๋‚ด์šฉ์ธ๋ฐ ๋งค๋ฒˆ DB์— insert/update์„ ํ•˜๊ธฐ์—๋Š” ์ฝ”๋“œ๊ฐ€ ์—ฌ๊ธฐ์ €๊ธฐ ๋“ค์–ด๊ฐ€๊ฒŒ ๋˜๋‹ˆ๊นŒ ์ƒ์„ฑ๋  ๋•Œ ๊ฐ™์ด ์ƒ์„ฑ๋˜๋ฉด ํŽธ๋ฆฌํ•˜๋‹ค! domain ํด๋”์— BaseTimeEntityํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์–ด์ฃผ๊ณ  ๋ชจ๋“  Entity์˜ ์ƒ์œ„ ํด๋ž˜์Šค๊ฐ€ ๋˜๊ฒŒ ํ•˜๋ฉด ๋œ๋‹ค. 1. @MappedSpuerclass ๋ฅผ ์ด์šฉํ•˜๋ฉด JPA Entityํด๋ž˜์Šค๋“ค์ด BaseTimeEntity๋ฅผ ์ƒ์†ํ•  ๊ฒฝ์šฐ ํ•„๋“œ๋“ค๋„ ์ปฌ๋Ÿผ์œผ๋กœ ์ธ์‹ํ•˜๋„๋ก ํ•œ๋‹ค. 2. @EntityListeners(AuditingEntityListener.class)๋กœ ํ•ด๋‹น ํด๋ž˜์Šค์— Auditing๊ธฐ๋Šฅ์„ ํฌํ•จํ•œ๋‹ค. 3. @CreatedDate priva..
//postRepository์—์„œ ๋„˜์–ด์˜จ ๊ฒฐ๊ณผ๋ฅผ postsRepository.findAllDesc().stream() //Stream์„ ํ†ตํ•ด map์œผ๋กœ new PostsListResponseDto ์— ๋งคํ•‘ ํ•ด์ค€๋‹ค. //PostsListResponseDto์—์„œ๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ postRepository์—์„œ ๋„˜์–ด์˜จ ๊ฒฐ๊ณผ Entity posts๋ฅผ ๋ฐ›๊ณ  ์žˆ์œผ๋ฏ€๋กœ //๊ฒฐ๊ณผ์ ์œผ๋กœ .map(posts -> new PostsListResponseDto(posts)) .map(PostsListResponseDto::new) //collect๋ฅผ ์‚ฌ์šฉํ•ด์„œ List๋กœ ๋ณ€ํ™˜ํ•œ๋‹ค. .collect(Collectors.toList()); stream์ด๋ผ๋Š” ๊ฒŒ ์žˆ๋Š” ๊ฒƒ ์กฐ์ฐจ ๋ชฐ๋ผ์„œ ๊ณต๋ถ€ํ•˜๋ฉด์„œ ํ˜ผ๋ž€์Šค๋Ÿฌ์› ๋‹ค ๋žŒ๋‹ค์‹์„ ๋ฐฐ์šด ์ ์ด ์—†์œผ๋‹ˆ. ใ… ..
์• ์ •์“ฐ
'spring-boot' ํƒœ๊ทธ์˜ ๊ธ€ ๋ชฉ๋ก