Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
76 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,28 @@ | ||
plugins { | ||
id 'java' | ||
id 'org.springframework.boot' version '2.7.7' | ||
id 'io.spring.dependency-management' version '1.0.15.RELEASE' | ||
id 'java' | ||
id 'org.springframework.boot' version '2.7.7' | ||
id 'io.spring.dependency-management' version '1.0.15.RELEASE' | ||
} | ||
|
||
group = 'hello' | ||
version = '0.0.1-SNAPSHOT' | ||
sourceCompatibility = '8' | ||
|
||
repositories { | ||
mavenCentral() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
|
||
implementation 'org.springframework.boot:spring-boot-starter-jdbc' | ||
runtimeOnly 'com.h2database:h2' | ||
// implementation 'org.springframework.boot:spring-boot-starter-jdbc' | ||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' | ||
runtimeOnly 'com.h2database:h2' | ||
|
||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
} | ||
|
||
tasks.named('test') { | ||
useJUnitPlatform() | ||
useJUnitPlatform() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/hello/hellospring/repository/JpaMemberRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package hello.hellospring.repository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import javax.persistence.EntityManager; | ||
|
||
import hello.hellospring.domain.Member; | ||
|
||
public class JpaMemberRepository implements MemberReository { | ||
private final EntityManager em; | ||
|
||
public JpaMemberRepository(EntityManager em) { | ||
this.em = em; | ||
} | ||
|
||
@Override | ||
public Member save(Member member) { | ||
em.persist(member); | ||
return member; | ||
} | ||
|
||
@Override | ||
public Optional<Member> findById(Long id) { | ||
Member member = em.find(Member.class, id); | ||
return Optional.ofNullable(member); | ||
} | ||
|
||
@Override | ||
public Optional<Member> findByName(String name) { | ||
List<Member> result = em.createQuery("select m from Member m where m.name = :name", Member.class) | ||
.setParameter("name", name) | ||
.getResultList(); | ||
return result.stream().findAny(); | ||
} | ||
|
||
@Override | ||
public List<Member> findAll() { | ||
return em.createQuery("select m from Member m", Member.class) // 객체 대상으로 날리는 쿼리 | ||
.getResultList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters