[ Java ] - JAP 환경 설정 / DB-H2 (1)
🔨 프로젝트 생성
인텔리제이 - Spring Initializr
- Type: Gradle
- Language: Java
- Java Version: 11
- Type: Gradle
< Dependencies >
- Lombok
- Spring Web
- Spring Data JPA
- H2 Database
- MySQL Driver
🔨 H2 웹콘솔 띄워보기
경로 : src > main > resources > application.properties
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb;MODE=MYSQL;
spring.jpa.show-sql=true
- Application.java 파일 run
- http://localhost:8080/h2-console 로 접속
- CREATE TABLE / INSERT / SELECT 해보기
🔨 패키지 구성
- controller
- entity
- repository
- service
- dto
- domain
🔨 JAP
경로: build.gradle
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
*Gradle devtool - mvnRepository에서 검색해서 맞는버전 사용하면 됨 (필수x)
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools
implementation 'org.springframework.boot:spring-boot-devtools:2.7.3'
📌 Controller
클라이언트의 요청을 받아서 처리하고 다시 응답값을 클라이언트에 보내는 역할
📌Service
비지니스적인 로직이 이루어지는 부분
Repository를 필요로 하기 때문에 처음에 명시해주어야 함
📌Repository
DB영, 자바소스로DB를 조작하기 위한 부분
📌Lombok
자바 프로젝트를 진행하는데 거의 필수적으로 필요한 메소드/생성자 등을 자동생성해줌으로써 코드를 절약할 수 있도록 도와주는 라이브러리
@Getter : get 메소드 생성
@Setter : set 메소드 생성
@AllArgsConstructor : 전체 멤버변수를 파라미터로 가지는 생성자 생성
@NoArgsConstructor : 기본생성자 생성
등등
📌DTO
Data Tramsfer Object의 약자
함부로 테이블을 건드리는 일을 최대한 지양해야 함
=> 완충제 역할을 함