-
2 minute read
๐ JPA Auditing src/main/java/com/test/spring/boot_crud/domain/BaseTimeEntity.java package com.test.spring.boot_crud.domain; import lombok.Getter; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import javax.persistence.EntityListeners; import javax.persistence.MappedSuperclass; import java.time.LocalDateTime; @Getter @MappedSuperclass @EntityListeners(AuditingEntityListener.class) public class BaseTimeEntity { @CreatedDate private LocalDateTime createdDate; @LastModifiedDate private LocalDateTime modifiedDate; } Posts ํด๋์ค๋ ์์ ํด์ฃผ์. ... public class Posts extends BaseTimeEntity { ... JPA Auditing :...
Continue reading...
-
2 minute read
๐ Controller src/main/java/com/test/spring/boot_crud/web/PostsApiController.java package com.test.spring.boot_crud.web; import com.test.spring.boot_crud.service.posts.PostsService; import com.test.spring.boot_crud.web.dto.PostsSaveRequestDto; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; @RequiredArgsConstructor @RestController public class PostsApiController { private final PostsService postsService; @PostMapping("/api/posts") public Long save(@RequestBody PostsSaveRequestDto requestDto) { return postsService.save(requestDto); } } @RequiredArgsConstructor : ์์กด์ฑ ์ฃผ์
(Dependency Injection) ํ์ฉ์ ์ํด ์ฌ์ฉ / final ํ๋๋ @NotNull์ด...
Continue reading...
-
1 minute read
๐ Mustache ๋จธ์คํ
์น(Mustache)๋ฅผ ์ด์ฉํด ํ๋ฉด์ ๋ง๋ค์ด๋ณด์. ํ๋ฌ๊ทธ์ธ ์ค์น ํ โก๏ธ dependencies { ... implementation('org.springframework.boot:spring-boot-starter-mustache') ... } build.gradle > dependencies์ ์์ ๊ฐ์ด ์ถ๊ฐ โก๏ธ ์ค๋ฅธ์ชฝ ์๋จ์ ๋จ๋ ๐๐๋ฅผ ๋๋ฌ์ฃผ์. ๐ Index ํ๋ฉด ๋ง๋ค๊ณ ์คํํด๋ณด๊ธฐ resources/templates/layout/header.mustache <!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>์คํ๋ง๋ถํธ ๊ฒ์ํ</title>...
Continue reading...
-
1 minute read
๐ ์คํ๋ง ๋ถํธ ํ๋ก์ ํธ ๋ง๋ค๊ธฐ ๐ค Spring Initializr๋ฅผ ์ด์ฉํ ์คํ๋ง ๋ถํธ ํ๋ก์ ํธ ์์ฑํ๊ธฐ Dependencies์๋ Spring Web Spring Data JPA Lombok MySQL Driver ๋ฅผ ์ถ๊ฐํด์ฃผ์. ๐ JPA๋? Java Persistence API ์๋ฐ ์ง์์์ ORM(Object-Relational Mapping) ๊ธฐ์ ํ์ค์ผ๋ก ์ฌ์ฉ๋๋ ์ธํฐํ์ด์ค์ ๋ชจ์ ORM : ์ ํ๋ฆฌ์ผ์ด์
์ ๊ฐ์ฒด๋ฅผ RDB ํ
์ด๋ธ์ ๋งคํ, ์๋์ผ๋ก ์์ํ ํด์ฃผ๋ ๊ฒ MyBatis,...
Continue reading...
-
2 minute read
๐ ์๋ฐ ์๊ณ ๋ฆฌ์ฆ ๋ฌธ์ ํ์ด ๐ ๋จ์ด ๋ค์ง์ด์ ์ถ๋ ฅํ๊ธฐ n๊ฐ์ ๋จ์ด๋ฅผ ์
๋ ฅ๋ฐ์ ํ, ์
๋ ฅ ๋ฐ์ ๋จ์ด๋ค์ ๋ค์ง์ด์(์ญ์ผ๋ก) ์ถ๋ ฅํด๋ณด์. // ์ถ๋ ฅ๊ฒฐ๊ณผ 3 hello java salut olleh avaj tulas ๐ ๋ฌธ์ ๋ค์ง๊ธฐ ๋ณธ ๋ฌธ์ ํ๊ธฐ ์ ์ ๋ฌธ์์ด ํ ๊ฐ๋ฅผ ์
๋ ฅ๋ฐ์ ๋ค์ง์ด์ ์ถ๋ ฅํด๋ณด๊ธฐ. import java.util.Scanner; public class Main { public static void main(String[] args){...
Continue reading...