1. 개발용 DB 연결 설정 (MySQL 기준)

1) build.gradle 라이브러리 추가


// jdbc와 MySQL 드라이버를 추가해야 해
dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-jdbc'
    runtimeOnly 'com.mysql:mysql-connector-j'
}

🔎 설명:

2) application.properties 설정

src/main/resources/application.properties


spring.datasource.url=jdbc:mysql://localhost:3306/데이터베이스명?serverTimezone=Asia/Seoul
spring.datasource.username=아이디
spring.datasource.password=비밀번호
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=none

🔎 설명:

2. 스프링 데이터 JPA 리포지토리 (MySQL 버전)

📄 SpringDataJpaMemberRepository.java

✅ Spring Data JPA가 자동으로 save()를 구현해줌!

package hello.hellospring.repository;

import hello.hellospring.domain.Member;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface SpringDataJpaMemberRepository extends JpaRepository<Member, Long>, MemberRepository {
    Optional<Member> findByName(String name);
}