일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Lesson2
- 리눅스
- QA엔지니어
- Java
- binaray_gap
- 프로그래머스
- database연결
- BC렌트
- 파이도 환불
- FLEX5
- IntelliJ
- 데이터의 무결성
- 자바
- 언마운트
- 엔테크서비스
- Lesson3
- 벤쿠버렌트
- FIDO 환불
- codility
- 레노보노트북
- 벤쿠버 렌트
- 부산입국
- 백준알고리즘
- FK 설정
- 벤쿠버집구하기
- 설탕문제
- 외래키설정
- Linux
- 캐나다워홀
- 1463번
- Today
- Total
대충이라도 하자
Spring Boot Tutorial | Full Course [2021] (5) 본문
다음은 Data Access Layer!
Application.properties파일에 아래와 같이 입력
<복사 붙여넣기할 내용!>
#Configuration to connect to Database
spring.datasource.url=jdbc:postgresql://localhost:5432/student
spring.datasource.username=
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.format_sql=true
*** PostgreSQL을 사용하기에 앞서, 다운로드 받아야 함
1. 다운 받은 후, SQL shell에서 로그인 한 후,
Create database student;
Grant all privileges on database '데이터베이스명' to '사용자이름';
으로 grant 하기
2. 주석 처리했던 JPA dependency 다시 해제하고 run 해서 오류없이 데이터베이스 연결되는지 확인
3. 다시 모델인 student클래스로 돌아옵니다.
아래와 같이 어노테이션 추가
4. 그러고 나서 실행하면 아래와 같이 나온다.
sequence start 1 increment 1은
위의 SequenceGenerator에서 allocationSize를 1로 해주었기 때문에 increment가 1로 나옴
JPA에서는 기본적으로 sql쿼리를 작성해주기에 작성할 필요가 없다는 장점이 있음!!!
다음은 save를 해보자! (sql구문으로 따지면 insert)
1. studentConfig클래스를 생성
2.StudentConfig클래스를 이런 식으로 작성해줌
3. 실행해보면!!!
이런 식으로 자동적으로 insert되는 것을 확인할 수 있다.
테이블에도 아래와 같이 잘 들어있음!!!
url을 통해서도 getStudent()메소드를 잘 수행하는 것을 확인할 수 있다.
///////////////
여기까지 getMapping으로 데이터 가져왔습니다.
다음은 Post, put, delete!!!
'꼬꼬마 개발자 노트 > Spring' 카테고리의 다른 글
Spring Boot Tutorial | Full Course [2021] (7) (0) | 2021.06.11 |
---|---|
Spring Boot Tutorial | Full Course [2021] (6) (0) | 2021.06.11 |
Spring Boot Tutorial | Full Course [2021] (4) (0) | 2021.06.11 |
Spring Boot Tutorial | Full Course [2021] (3) (0) | 2021.06.11 |
Spring Boot Tutorial | Full Course [2021] (2) (0) | 2021.06.11 |