Server/Java 6

Java) JpaRepository - Rollback Test

패키지 구성은 다음을 참고해주세요. https://juzdalua.tistory.com/102 Java) JpaRepository - MySQL 데이터 가져오기 먼저 세팅이다. 프로젝트를 만들 때 디펜던시는 다음과 같다. 실제 코드에서의 디펜던시이다. // build.gradle ... dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' testImplementation 'org.spring juzdalua.tistory.com 유저테이블에 유저를 신규 생성하는 과정에서 트랜잭션 과정 중 에러가 나면 롤백을 할 수 있는지 테스트를 해보았다. 1. 올바른 데이터의 유저를 저장한다. 2. 잘못된 데이터의 유저를 저장..

Server/Java 2022.11.17

Java) JpaRepository - MySQL Post method, Raw Query

기본 세팅과 조회는 아래 글을 참고해주세요. https://juzdalua.tistory.com/102 Java) JpaRepository - MySQL 데이터 가져오기 먼저 세팅이다. 프로젝트를 만들 때 디펜던시는 다음과 같다. 실제 코드에서의 디펜던시이다. // build.gradle ... dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' testImplementation 'org.spring juzdalua.tistory.com 이번에는 INSERT, UPDATE를 진행해보려 한다. DAO, DTO, VO, Entity를 구분해야 하지만 편의상 Dto 하나로 진행했다. UPDATE시 userId만 바디로..

Server/Java 2022.11.17

Java) JpaRepository - MySQL 데이터 가져오기

먼저 세팅이다. 프로젝트를 만들 때 디펜던시는 다음과 같다. 실제 코드에서의 디펜던시이다. // build.gradle ... dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' testImplementation 'org.springframework.boot:spring-boot-starter-test' // Mysql implementation 'org.springframework.boot:spring-boot-starter-data-jpa' runtimeOnly 'com.mysql:mysql-connector-j' } 로컬 디비를 사용했다. // application.properties # JPA spring..

Server/Java 2022.11.16

Java) 컴포넌트 스캔으로 자동 DI 주입하기

Controller -> Service -> Repository Java는 위처럼 서비스 로직이 구현된다. Component annotation(@)을 활용하면 각 클래스마다 객체를 생성하여 스프링 빈에 저장한다. @Controller, @Service, @Repository 어노테이션을 클릭하여 들어가면 @Component 어노테이션을 포함하는 것을 알 수 있다. 서비스 클래스에서 레포 클래스를 가져다가 쓰고 싶다면 아래처럼 구현할 수 있다. public class MemberService { private final MemberRepository memberRepository = new MemberRepository(); } 하지만 이런 서비스 클래스가 많아진다면 동일한 레포 클래스 객체를 계속하여 ..

Server/Java 2022.11.16

Java) Spring Boot로 Java 시작하기 (VSCode - Mac M1)

맥북은 자바가 기본적으로 설치되어있다. 아래 익스텐션 두개만 설치하면 JVM, Tomcat 등 다양한 라이브러리를 기본적으로 설치해준다. VSC Extension Extension Pack for Java Gradle for Java 먼저 프로젝트를 생성한다. https://start.spring.io/ Generate 버튼을 누르면 zip파일이 다운로드되고 압축을 풀고 해당 폴더에서 vsc를 키면 된다. 8080포트에 기본적으로 서버가 잡힌다. Build 하는 방법은 아래와 같다. # 현재 폴더: Project # build ./gradlew build # build 삭제 ./gradlew clean # 다시 build ./gradlew clean build 아래는 Run 버튼 이외에 터미널에서 프로젝..

Server/Java 2022.11.14