[Lotto springboot+JPA] 1. 프로젝트 생성

Welcome to Seoyun Dev Log·2022년 7월 4일
0

01. start.spring.io

설정

: 기존 build.gradle 파일 변경

plugins {
	id 'org.springframework.boot' version '2.7.1'
	id 'io.spring.dependency-management' version '1.0.11.RELEASE'
	id 'java'
}

group = 'jpabook'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

configurations {
	compileOnly {
		extendsFrom annotationProcessor //lombok
	}
}

repositories {
	mavenCentral() //mavenCentral에서 라이브러리 다운 받겠다는것
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
	implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
	implementation 'org.springframework.boot:spring-boot-starter-validation'
	implementation 'org.springframework.boot:spring-boot-starter-web'
	implementation 'org.springframework.boot:spring-boot-devtools'
	implementation 'mysql:mysql-connector-java'
	implementation 'org.projectlombok:lombok:1.18.12'
	implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.5.6'
	compileOnly 'org.projectlombok:lombok'
	annotationProcessor 'org.projectlombok:lombok'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
	useJUnitPlatform()
}

test {
	useJUnitPlatform()
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
	implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
	implementation 'org.springframework.boot:spring-boot-starter-validation'
	implementation 'org.springframework.boot:spring-boot-starter-web'
	implementation 'org.springframework.boot:spring-boot-devtools'
	implementation 'mysql:mysql-connector-java'
    implementation 'org.projectlombok:lombok:1.18.12'
    implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.5.6'
    implementation 'com.google.code.gson:gson:2.8.5'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    runtimeOnly 'com.h2database:h2'

	implementation 'javax.xml.bind:jsxb-api'
	implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5'
	implementation 'io.jsonwebtoken:jjwt-impl:0.11.5'

	// TEST
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testImplementation 'org.junit.jupiter:junit-jupiter-api'
	testImplementation 'org.junit.jupiter:junit-jupiter-params'
	testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'

	testImplementation 'io.rest-assured:rest-assured:3.3.0'

	// 빌드
	//implementation 'org.glassfish.jaxb:jaxb-runtime'

}

application.yml로 변경

: 🚩logging 추가해야함

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/Lotto?
    username: root
    password: 232323
    driver-class-name: com.mysql.cj.jdbc.Driver

  jpa:
    hibernate:
      ddl-auto: validate
    properties:
      hibernate:
#        show_sql: true
        format_sql: true

logging:
  level:
    org.hibernate.sql: debug
#    org.hibernate.type: trace 파라미터에 뭐가 들어가는지 찍어줌

02. logback.xml-> 변경

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <!-- 로그파일 저장 경로 -->

    <!-- CONSOLE -->
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <Pattern>
                [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} : %30logger{5} - %msg%n
            </Pattern>
        </layout>
    </appender>
    <!-- // CONSOLE -->

    <root level="warn">
        <appender-ref ref="CONSOLE" />
    </root>
    <!--//구간 설정-->
    <logger name="lotto.practice.random.service" level="debug" additivity="false">
        <appender-ref ref="CONSOLE" />
    </logger>


</configuration>

03. 순서

    1. entity
    1. repository
    1. service
    1. domain
    1. web

04. 엔티티 매핑

: 예제는 편의를 위해서 jpa-ddl-auto를 create로 사용하였습니다
: String 길이 설정하기

@Table unique생성

@Table(name = "t_user",
        uniqueConstraints = @UniqueConstraint(
            name = "unique",
            columnNames = {"f_user_id","f_user_pw", "f_user_email"}
        ))

nullable과 @Notnull의 차이

https://kafcamus.tistory.com/15

05. 동행복권 API

gson 사용하여 url 파싱하기

https://www.wake-up-neo.com/ko/java/url%EC%97%90%EC%84%9C-json-%ED%8C%8C%EC%8B%B1/940071612/

profile
하루 일지 보단 행동 고찰 과정에 대한 개발 블로그

0개의 댓글