공부이야기/[Spring.210428~]15 [스프링 입문] 스프링 데이터 JPA 스프링 데이터 JPA는 JPA를 편리하게 사용하도록 도와주는 기술이다. JPA 학습 후 스프링 데이터 JPA 학습해야한다. - 스프링 데이터 JPA 회원 리포지토리 repository/SpringDataJpaMemberRepository 1 2 3 4 5 6 public interface SpringDataJpaMemberRepository extends JpaRepository, MemberRepository { @Override Optional findByName(String name); } Colored by Color Scripter cs · JpaRepository : Spring Data 제공 인터페이스만 있지만 JpaRepository를 가지고 있는 SpringDataJpa가 자동으로 구현체.. 2021. 5. 8. [스프링 입문] JPA JPA(Java Persistence API) 기본적인 SQL도 JPA가 직접 만들어서 실행해준다. SQL-데이터 중심의 설계에서 객체 중심의 설계로 패러다임을 전환할 수 있다. 개발 생산성을 높일 수 있다. - build.gradle 에 JPA, h2 데이터베이스 관련 라이브러리 추가 1 2 3 4 5 6 7 8 9 10 dependencies { implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-web' //implementation 'org.springframework.boot:spring-boot-starter-.. 2021. 5. 8. [스프링 입문] 스프링 JdbcTemplate ▷ 설정은 Jdbc와 동일한 환경설정이다. ▷ 스프링 JdbcTemplate과 MyBatis 같은 라이브러리는 JDBC API에서 본 반복 코드를 대부분 제거해주지만 SQL은 직접 작성해야한다. - 스프링 JdbcTemplate 회원 리포지토리 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152package hello.hellospring.repository;import hello.hellospring.domain.Member;import org.springframework.jdbc.core.JdbcTemplate;import org.springframework.jdbc.core.Row.. 2021. 5. 8. [스프링 입문] 스프링 통합 테스트 스프링 컨테이너 - DB 연결 - 회원 서비스 스프링 통합 테스트 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 package hello.hellospring.service; import hello.hellospring.domain.Member; import hello.hellospring.repository.MemberRepository; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.bo.. 2021. 5. 8. [스프링 입문] 순수 Jdbc 개방-폐쇄 원칙(OCP, Open-Closed Principle) : 확장에는 열려있고 수정, 변경에는 닫혀있다. 스프링의 DI(Development Injection)을 사용하면 기존 코드를 손대지 않고, 설정만으로 구현클래스 변경 O 데이터를 DB에 저장하므로 스프링 서버를 다시 실행해도 데이터가 안전하게 저장된다. - 스프링 부트 데이터베이스 연결 설정 추가 resources/application.properties 1 2 3 spring.datasource.url=jdbc:h2:tcp://localhost/~/test spring.datasource.driver-class-name=org.h2.Driver spring.datasource.username=sa cs - Jdbc 회원 리포지토리 1 .. 2021. 5. 7. [스프링 입문] h2 설치 ▶설치 링크 www.h2database.com/html/main.html H2 Database Engine H2 Database Engine Welcome to H2, the Java SQL database. The main features of H2 are: Very fast, open source, JDBC API Embedded and server modes; in-memory databases Browser based Console application Small footprint: around 2 MB jar file size Suppor www.h2database.com 1. Windows Installer로 다운 2. 설치 후 실행 JDBC URL을 다음과 같이 변경한다. -> 파일을 직접 .. 2021. 5. 6. [스프링 입문] 자바 코드로 스프링 빈 등록 1. 스프링 빈을 등록하는 2가지 방법 - 컴포넌트 스캔(ex. @Service, @~) 과 자동 의존관계 설정 - 자바 코드로 직접 스프링 빈 등록하기 1) 자바 코드로 직접 스프링 빈 등록하기 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 package hello.hellospring; import hello.hellospring.repository.MemberRepository; import hello.hellospring.repository.MemoryMemberRepository; import hello.hellospring.service.MemberService; import org.springframework.context.annotat.. 2021. 5. 6. [스프링 입문] 컴포넌트 스캔과 자동 의존관계 설정 MVC, 템플릿 엔진 이미지 helloController 안에 애노테이션이 있으면 Spring이 뜰 때 생성하여 알아서 관리한다. 1. 스프링 빈을 등록하는 2가지 방법 - 컴포넌트 스캔(ex. @Service, @~) 과 자동 의존관계 설정 - 자바 코드로 직접 스프링 빈 등록하기 1) 컴포넌트 스캔과 자동 의존관계 설정 - @Component : 애노테이션이 있으면 스프링 빈으로 자동 등록된다. - @Controller : 컨트롤러가 스프링 빈으로 자동 등록된 이유도 컴포넌트 스캔 때문이다. - @Component 를 포함하는 다음 애노테이션도 스프링 빈으로 자동 등록된다. - @Controller - @Service - @Repository 더보기 + 아무곳이나 @Componet를 해도 되는가? 우.. 2021. 5. 6. 이전 1 2 다음