Spring

✍ AOP가 필요한 상황 ✔ 모든 메서드의 호출 시간을 측정하고 싶다면? ✔ 공통 관심 사항(cross-cutting concern) vs 핵심 관심 사항(core concern) ✔ 회원 가입 시간, 회원 조회 시간을 측정하고 싶다면? 💻 회원 가입 시간 측정 public Long join(Member member){ // 시간 측정 long start = System.currentTimeMillis(); try { validateDuplicateMember(member); // 중복 회원 검증 memberRepository.save(member); return member.getId(); } finally { long finish = System.currentTimeMillis(); long time..
✍ 스프링 데이터 JPA 스프링 부트와 JPA만 사용해도 개발 생산성이 정말 많이 증가하고, 개발해야 할 코드도 확연이 줄어든다. 여기에 스프링 데이터 JPA를 사용하면, 기존의 한계를 넘어 마치 마법처럼, 리포지토리에 구현 클래스 없이 인터페이스 만으로 개발을 완료할 수 있다. 그리고 반복 개발해온 기본 CRUD 기능도 스프링 데이터 JPA가 모두 제공한다. 스프링 부트와 JPA라는 기반 위에, 스프링 데이터 JPA라는 환상적인 프레임워크를 더하면 개발이 정말 즐거워 진다. 지금까지 조금이라도 단순하고 반복이라 생각했던 개발 코드들이 확연하게 줄어든다. 따라서 개발자는 핵심 비즈니스 로직을 개발하는 데 집중할 수 있다. 실무에서 관계형 데이터베이스를 사용한다면 스프링 데이터 JPA는 이제 선택이 아니라..
✍ JPA ✔ JPA는 기존의 반복 코드는 물론이고, 기본적인 SQL도 JPA가 직접 만들어서 실행해준다. ✔ JPA를 사용하면 SQL과 데이터 중심의 설계에서 객체 중심의 설계로 패러다임을 전환할 수 있다. ✔ JPA를 사용하면 개발 생산성을 크게 높일 수 있다. 💻 build.gradle 파일에 JPA, h2 데이터베이스 관련 라이브러리 추가 spring-boot-starter-data-jpa는 내부에 jdbc 관련 라이브러리를 포함한다. 따라서 jdbc는 제거해도 된다. 💻 resources/application.properties 설정 추가 💻 @Entity와 PK 매핑 package hello.hellospring.domain; import javax.persistence.Entity; impo..
💻 h2 Database 설치 drop table if exists member CASCADE; create table member ( id bigint generated by default as identity, name varchar(255), primary key (id) ); ✍ 순수 JDBC 가볍게 듣고 넘기기 ~ ✍ 스프링 통합 테스트 스프링 컨테이너와 DB까지 연결된 통합 테스트를 진행 ✔ 개방-폐쇄 원칙(OCP, Open-Closed Principle_ 확장에는 열려있고, 수정, 변경에는 닫혀있다. ✔ 스프링의 DI(Dependencies Injection)을 사용하면 기존 코드를 전혀 손대지 않고, 설정만으로 구현 클래스를 변경할 수 있다. ✔ 회원을 등록하고 DB에 결과가 잘 입력되는지..
✍ 회원 웹 기능 - 홈 화면 추가 💻 HomeController 생성 package hello.hellospring.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @Controller public class HomeController { @GetMapping("/") public String home() { return "home"; } } 💻 home.html 생성 Hello Spring 회원 기능 회원 가입 회원 목록 🔍 그럼 왜 기존에 생성된 hello-static.html이 실행되지 않고 home.html이 먼저 생성될 까? -..
✍ 스프링 빈을 등록하고, 의존관계 설정하기 회원 컨트롤러가 회원서비스와 회원 리포지토리를 사용할 수 있게 의존관계를 준비하자 💻 MemberController 생성 package hello.hellospring.controller; import org.springframework.stereotype.Controller; @Controller public class MemberController { } 💻 @Autowired @Controller public class MemberController { private final MemberService memberService; @Autowired public MemberController(MemberService memberService) { this...
✍ 비즈니스 요구사항 정리 - 데이터 : 회원 ID, 이름 - 기능: 회원 등록, 조회 - 아직 데이터 저장소가 선정되지 않음(가상의 시나리오) ✍ 일반적인 웹 애플리케이션 계층 구조 - 컨트롤러: 웹 MVC의 컨트롤러 역할 - 서비스: 핵심 비즈니스 로직 구현 - 리포지토리: 데이터베이스에 접근, 도메인 객체를 DB에 저장하고 관리 - 도메인: 비즈니스 도메인 객체 / 예) 회원, 주문, 쿠폰 등등 주로 데이터베이스에 저장하고 관리됨 ✍ 클래스 의존관계 - 아직 데이터 저장소가 선정되지 않아서, 우선 인터페이스로 구현 클래스를 변경할 수 있도록 설계 - 데이터 저장소는 RDC, NoSQL 등등 다양한 저장소를 고민중인 상황으로 가정 - 개발을 진행하기 위해서 초기 개발 단계에서는 구현체로 가벼운 메모리..
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; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class HelloController { @GetMapping("hello-string") @ResponseBody public ..
✍ MVC Model, View, Controller 💻 Controller package hello.hellospring.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @Controller public class HelloController { @GetMapping("hello") public String hello(Model model){ model.addAttribute("data", "hello!!"); return "hello"; } } 💻 View 안녕하세요. ..
✍ 웹을 개발하는 방법에는 크게 3가지 방법이 있다. 정적 컨텐츠 MVC와 템플릿 엔진 API 정적 컨텐츠 입니다.
suniverse
'Spring' 카테고리의 글 목록