반응형

분류 전체보기 294

15. 스프링 DB 접근 기술 | 순수 Jdbc | 스프링 통합 테스트 @Transactional, @SpringBootTest

환경설정 build.gradle 파일에 jdbc, h2 데이터베이스 관려 라이브러리 추가 implementation 'org.springframework.boot:spring-boot-starter-jdbc' runtimeOnly 'com.h2database:h2' build.gradle plugins { id 'org.springframework.boot' version '2.7.0' // 스타터 사이트에서 선택한 버전 id 'io.spring.dependency-management' version '1.0.11.RELEASE' id 'java' } group = 'hello' version = '0.0.1-SNAPSHOT' sourceCompatibility = '11' repositories { /..

13. 회원 웹 기능 - 조회 | th : each =" " | ${ } → Model 안에 있는 Data를 꺼내는것

memberList.html th : each =" " → 타임리프 문법. 자바의 forEach 같음 ${ } → Model 안에 있는 Data를 꺼내는것 # 이름 MemberController.java package hello.hellospring.controller; import hello.hellospring.domain.Member; import hello.hellospring.service.MemberService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import o..

12. 회원 웹 기능 - 등록 | @PostMapping | redirect:/

createMemberForm.html 이름 등록 MemberForm.java package hello.hellospring.controller; public class MemberForm { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } } MemberController.java package hello.hellospring.controller; import hello.hellospring.domain.Member; import hello.hellospring.service.MemberService; import org.springframew..

10. 자바 코드로 직접 스프링 빈 등록하기 | Spring이 @Configuration를 읽고 Spring Bean에 등록해준다.

전 게시물의 회원 서비스와 회원 리포지터리의 @Service, @Repository, @Autowired 어노테이션을 제거하고 진행한다. SpringConfig.java package hello.hellospring.service; import hello.hellospring.repository.MemberRepository; import hello.hellospring.repository.MemoryMemberRepository; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class SpringConfig ..

★ 9. 컴포넌트 스캔과 자동 의존관계 설정 | @Controller, @Autowired, @Service, @Repository

1. 회원 컨트롤러에 의존관계 추가 - 스프링 빈을 등록하고, 의존관계 설정하기 - Member Controller가 Member Service와 Member Repository를 사용할 수 있게 의존관계를 준비하자 - Controller와 Service가 연결되는걸 의존한다고 한다 MemberController package hello.hellospring.controller; import hello.hellospring.service.MemberService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @Controller public clas..

8. 회원 서비스 개발 | 회원 서비스 테스트

리포지터리는 단순하게 저장소에 값을 넣다 빼는 느낌이면 서비스는 비지니스에 가깝다. 메서드 명도 비지니스에 가깝게 지어야한다. 그래야 회원가입 관련 이슈를 받았을때 Join 메서드 살펴보자 하면서 비지니스 문제를 찾을수 있다. 이렇게 서비스는 비지니스에 의존적이게 설계를 해야하고 리포지터리는 단순히 기계적으로 개발스럽게 용어를 선택한다. (insert, update..등) 회원 서비스 개발 ifPresent - null이 아니라 어떤 값이 있으면 동작하는 메서드 - Optional로 감쌌기 때문에 가능한 기능이다. 과거에는 if문 사용해서 null 체크했던걸 현재는 ifPresent로 생략한 모습 - Optional로 한번 감싸면 Optional 안에 member 객체가 있는것. - 그냥 꺼내고 싶으면 ..

7. 회원 도메인과 리포지토리 생성 | 테스트 케이스 작성

domain package hello.hellospring.domain; public class Member { private Long id; private String name; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } repository package hello.hellospring.repository; import hello.hellospring.domain.Member; import java.util.List; import ..

6. 비지니스 요구사항 정리 | 일반적인 웹 애플리케이션 계층 구조

회원 관리 예제 - 백엔드 개발 - 비지니스 요구사항 정리 - 회원 도메인과 리포지토리 만들기 - 회원 리포지토리 테스트 케이스 작성 - 회원 서비스 개발 - 회원 서비스 테스트 비지니스 요구사항 정리 - 데이터 : 회원ID, 이름 - 기능 : 회원 등록, 조회 - 아직 데이터 저장소가 선정되지 않음 (가상의 시나리오) 일반적인 웹 애플리케이션 계층 구조 클래스 의존관계

반응형