java11, spring boot(2.7.11), mySQL(8.0.30), gradle(7.6.1)
의존성에 mySQL Driver, Spring Data API를 추가(아래는 spring web, JDBC까지 추가한 상태)
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.11'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'com.mysql:mysql-connector-j'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
# MySQL 설정
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# DB Source URL
spring.datasource.url=jdbc:mysql://localhost:3306/tentative_IRIRO(schema name)?
serverTimezone=UTC&characterEncoding=UTF-8
# DB 계정명 및 비밀번호
spring.datasource.username=계정명
spring.datasource.password=비밀번호
# MySQL 설정
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# DB Source URL
spring.datasource.url=jdbc:mysql://localhost:3306/tentative_IRIRO(schema name)?
serverTimezone=UTC&characterEncoding=UTF-8
# DB 계정명 및 비밀번호
spring.datasource.username=계정명
spring.datasource.password=비밀번호
# JPA 쿼리문 확인 가능
spring.jpa.show-sql=true
# DB의 고유 기능 사용 가능
spring.jpa.hibernate.ddl-auto=update
# SQL의 가독성 높임(JPA 구현체인 Hibernate 동작)
spring.jpa.properties.hibernate.format_sql=true
import lombok.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import javax.persistence.*;
@ToString
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "test")
public class Test {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long test_id;
@Column(name="t",nullable = false)
private String textText;
}