DB connection in Springframework

Hayoung Kim·2020년 7월 8일
0

SpringFramework

목록 보기
2/9

domain

JPA

Java Persistance Api

domain.dto : Entity를 정의한다.

데이터베이스에 정의되어있는 엔티티 형태를 정의.
@Data //lombok anntation을 사용하면 자동으로 getter, setter가 생성된다.

domain.repository : interface

public interface UserRepository extends JpaRepository<User, Long> {
...

<User, Long> = <dto, pk's type>

application.properties에서 설정하는 방법

ORM(Object Relative Mapping)::Hibernate

  • spring.jpa.hibernate.ddl-auto=update
    create : Create the schema and destroy previous data.
    udpate : Update schema if necessary.

  • spring.jpa.show-sql=true
    실제 query를 보여줌.

h2 사용방법

spring.h2.console.path=/console
spring.h2.console.enabled=true

localhost:port/console로 접속하면 Db에 들어가진다.

  • JdbcURL = spring.datasource.url
  • name = spring.datasource.username
  • password = spring.datasource.password

0개의 댓글