본문 바로가기

스프링 입문 - 코드로 배우는 스프링 부트11

(회원 관리 예제) 회원 서비스 테스트 mac : window 단축키 관련 ^ : ctrl ⬆ : shift 위에서 아래모양 : alt 이전 내용 다시 실행 : shift + f10 Create New Test : Ctrl + shift + t OK이후 Test에서는 메소드 이름을 한글로 적어도 된다. (실제 많이 사용된다.) 중복 정리 MemberServiceTest MemberService memberService = new MemberService(); @Test public void 중복_회원_예외(){ // given Member member1 = new Member(); member1.setName("spring"); Member member2 = new Member(); member2.setName("spring"); // whe.. 2021. 9. 26.
(회원 관리 예제) 회원 서비스 개발 서비스 클래스 : 메소드 name, business에서 사용되는 용어를 사용해야 한다. 이유 : 개발자, 기획자에서 어떠한 로직이 오류가 발생할 때 서비스 클래스에서 쉽게 찾을 수 있다. repository : 메소드 name, 기계적 용어를 사용한다. package hello.hellospring.service; import hello.hellospring.domain.Member; import hello.hellospring.repository.MemberRepository; import hello.hellospring.repository.MemoryMemberRepository; import java.util.List; import java.util.Optional; public class Memb.. 2021. 9. 26.
(회원 관리 예제) 회원 리포지토리 테스트 케이스 작성 개발한 기능을 실행해서 테스트 할 때 자바의 main 메서드를 통해서 실행하거나, 웹 애플리케이션의 컨트롤러를 통해서 해당 기능을 실행한다. 이러한 방법은 준비하고 실행하는데 오래 걸리고, 반복 실행하기 어렵고 여러 테스트를 한번에 실행하기 어렵다는 단점이 있다. 자바는 JUnit이라는 프레임워크로 테스트를 실행해서 이러한 문제를 해결한다. main/java/hello.hellospring/repository/MemberRepository package hello.hellospring.repository; import hello.hellospring.domain.Member; import java.util.List; import java.util.Optional; public interface Membe.. 2021. 9. 20.
(회원 관리 예제) 비즈니스 요구사항 정리 데이터 : 회원ID, 이름 기능 : 회원 등록, 조회 아직 데이터 저장소가 선정되지 않음(가상의 시나리오) 컨트롤러 : 웹 MVC의 컨트롤러 역할 서비스 : 핵심 비즈니스 로직 구현 리포지토리 : 데이터베이스에 접근, 도메인 객체를 DB에 저장하고 관리 도메인 : 비즈니스 도메인 객체, 예) 회원, 주문, 쿠폰 등등 주로 데이터베이스에 저장하고 관리된다. 아직 데이터 저장소가 선정되지 않아서, 우선 인터페이스로 구현 클래스를 변경할 수 있도록 설계 데이터 저장소는 RDB, NoSQL 등등 다양한 저장소를 고민중인 상황으로 가정 개발을 진행하기 위해서 초기 개발 단계에서는 구현체로 가벼운 메모리 기반의 데이터 저장소 사용 강의 주소 : https://www.inflearn.com/course/%EC%8A%.. 2021. 9. 20.
(스프링 웹 개발 기초) API @ResponseBody : HTTP의 BODY에 문자 내용을 직접 반환(HTML BODY TAG를 말하는 것이 아니다.) (1) @ResponseBody 문자 반환 @Controller public class HelloController { @GetMapping("hello-string") @ResponseBody public String helloString(@RequestParam("name") String name) { return "hello " + name; } } 실행 결과 package hello.hellospring.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model.. 2021. 9. 20.
(스프링 웹 개발 기초) MVC와 템플릿 엔진 Model, Controller : 비즈니스 로직, 내부 처리하는데 집중해야 한다. View : 화면 그리는 모든 영향 java/hello.hellospring/controller/HelloController package hello.hellospring.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; @Controller public class HelloContro.. 2021. 9. 20.