gwooden_코린이

스프링 부트 DB구축을 위한 JPA 활용 본문

스프링 부트

스프링 부트 DB구축을 위한 JPA 활용

gwooden22 2023. 2. 13. 13:21
728x90

1. 스프링 부트 DB구축을 위한 JPA 활용

 

새로 만들기에서 메모장 선택 후 위 이름 및 확장자명 넣어서 생성
경로에 맞춰서 링크 작성

# DATABASE
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
spring.datasource.url=jdbc:h2:d:/local
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=

# JPA
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update

package com.example.sb;


import java.time.LocalDateTime;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.Getter;
import lombok.Setter;


@Entity
@Getter
@Setter
public class Question {

	@Id 
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id; //질문코드
	
	@Column(length = 200) //varchar(200)
	private String subject;
	
	@Column(columnDefinition = "TEXT") //varchar
	private String content;
	
	private LocalDateTime createDate;
}


package com.example.sb;

import java.time.LocalDateTime;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.Getter;
import lombok.Setter;

@Entity
@Getter
@Setter
public class Answer {
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	
	@Column(columnDefinition = "TEXT")
	private String content;
	
	private LocalDateTime createDate;

}

728x90
Comments