Web
-
Spring boot - 정적 리소스 설정 변경Web/환경설정 관련 2024. 5. 10. 16:34
목적: 지금까지 스프링 혹은 부트를 사용하며, 여러 설정들을 적어 둔 것을 정리 하기 위해 작성 spring MVC에서 url로 들어온 클라이언트의 요청을 정적 리소스(html,css,javascript 등등) 혹은 동적 리소스(jsp 등 뷰 템플릿)를 활용해서 처리한다. 컨트롤러 메서드에 url을 맵핑하듯, 정적 리소스에도 접근 가능한 url 맵핑이 필요하다. 이에 대한 설정을 알아보자 1. classpath classpath란 빌드시 컴파일 된 class 파일들과 resources의 최상위 경로이다.설정 파일 (.yml, properties)는 해당 경로 아래 어느 곳이든 존재만 해야한다. Project Structure 탭을 통해 쉽게 확인할 수 있다. 2. 정적 리소스 기본 위치 다음 4가..
-
JPA (11) - 다형성 쿼리,엔티티 직접 사용,정적쿼리,벌크연산Web/JPA 2024. 1. 12. 14:40
1. 다형성 쿼리 - TYPE > 조회 대상을 특정 자식으로 한정 (ex Item 중에 Book, Movie를 조회하라) select i from Item i where type(i) IN (Book, Movie) > 자바의 타입 캐스팅과 유사하다. > 상속 구조에서 부모 타입을 특정 자식 타입으로 다룰 때 사용 (FROM, WHERE, SELECT에서 사용) select i from Item i where treat(i as Book).author = 'kim' 2. 엔티티 직접 사용 > JPQL에서 엔티티를 직접 사용하면 SQL에서 해당 엔티티 기본 키 값을 사용한다. select count(m.id) from Member m //엔티티 아이디를 사용 select count(m) from Member..
-
JPA 활용 (1) - 프로젝트 환경설정Web/JPA 2024. 1. 4. 14:24
1. spring boot (build.gradle) > java 17버전 > dependencies: spring-data-jpa, thymeleaf, validation,spring-web, h2 > gradle은 의존관계 추가하면, 그 의존관계에 필요한 모든 의존관계 자동으로 끌어온다. > ./gradlew dependencies -configuration complieClasspath를 보면 의존관계 라이브러리 살펴볼 수 있음 * dependencies 추가하면서, version이 없는 것은 , plugins에 작성된 것은 2. H2 데이터 베이스 설치 > jdbc:h2:~/jspshop (최소한번) -> 한번 들어가줘야함 파일 모드로 들어가기 > ~/jpashop.mv.db -> 파일 생성 한번..
-
스프링 핵심 원리 (4) - 컴포넌트 스캔Web/Spring 2023. 8. 18. 03:56
1. 컴포넌트 스캔과 의존관계 자동 주입 - 스프링 빈을 등록할 때 자바코드나 Xml을 통해 설정 정보를 직접 등록했음 - 설정 정보 없이 자동으로 스프링 빈을 등록하는 컴포넌트 스캔이라는 기능 있다. - 의존관계 자동 주입하는 @Autowired 기능도 제공한다. @Configuration @ComponentScan public class AutoAppConfig{ } > 컴포넌트 스캔을 사용하려면, 설정 정보에 @ComponentScan을 붙여주면 된다. > @Component 어노테이션이 붙은 클래스를 스캔해서 스프링 빈으로 등록한다. @Configuration도 스캔 대상이다. @Component public class MemoryMemberRepository implements MemberRep..
-
스프링 핵심 원리 (3) - 싱글톤 컨테이너Web/Spring 2023. 8. 17. 15:22
1. 스프링 컨테이너의 이점 (싱글톤) 1.1 앱 어플리케이션과 싱글톤 - 스프링은 기업용 온라인 서비스 기술을 지원하기 위해 탄생 - 스프링 어플리케이션은 대부분 웹 어플리케이션임 - 웹 어플리케이션은 보통 여러 고객이 동시 요청한다. AppConfig appConfig = new AppConfig() MemberService memberService1 = appConfig.memberService(); MemberService memberService2 = appConfig.memberService(); - 설정 클래스인 순수 DI 컨테이너 AppConfig를 사용해서 memberService를 생성해보자 - memberService()메서드는 내부적으로 생성자를 사용하여 구현체를 생성하므로, 요청시..
-
스프링 핵심 원리 (2) - 스프링 컨테이너와 스프링 빈Web/Spring 2023. 8. 17. 12:14
1. 스프링 컨테이너 생성 ApplicationContext applicationContext = new AnnotationConfigApplicationContext(AppConfig.class); - 위와 같이 스프링 컨테이너 생성, ApplicatoinContext는 인터페이스이다. (구현객체 어노테이션~,xml~등) - 스프링 컨테이너는 XML기반 혹은 애노테이션 기반으로 만들 수 있다. 1.1 스프링 컨테이너 생성 과정 - ApplicationContext 구현객체를 생성하면, 스프링 컨테이너에 빈 저장소가 생성되고, 파라미터로 넘어온 구성 정보를 통해 스프링 빈 저장소가 채워진다. - 빈 이름은 메서드명, 빈 객체는 리턴 값으로 채워진다. - 빈 이름은 직접 부여할 수 있다.( @Bean(na..
-
스프링 핵심 원리 (1) - 예제 순수 자바 to 스프링 컨테이너Web/Spring 2023. 8. 16. 18:49
- 객체 지향 프로그래밍의 원리에 맞게 회원 및 주문 서비스를 만들어보자 - 객체 지향 설계에서 협력 - 역할 - 책임의 관계는 매우 중요하다. 역할: 객체가 수행할 책임들을 의미하고, 다형적인 특징을 보여준다. 책임: 객체가 수행해야할 행위 공용인터페이스 - 객체지향- 다형적 특징은 역할과 구현을 분리함으로써 달성할 수 있다. 캡슐화: - 데이터 숨김, 내부 구현 숨김,메시지를 통한 데이터 접근 -> 객체 자율성 부여 - 오류의 범위 캡슐 내부화 -> 유지보수에 유리 타입: 객체를 나누는 기준 -> 할 수 있는 책임(행위)에 따라 객체 분리(classify) 클래스: 객체를 생성할 수 있도록 언어적 차원에서 지원된 정적 객체 생성 방법 - 객체지향적 설계에서 가장 중요한 것은 협력관계를 통해 적절히 책..
-
나프 - 게시판 만들기(1)Web/Spring 2023. 8. 2. 21:05
1. 3-Tier 방식의 이해 - Spring에서 DB 작업 간소화로 사용자 요구사항을 반영하고, 컨트롤러 비대해지는 것을 방지하기 위해 - Presentation Tier Persistence Tire의 3개의 Tire로 나누어 요청을 처리한다. Presentation: 웹/화면 계층, Controller(FrontController+POJO),JSP를 이용한 VIEW구성 담당 Business Tire : 비지니스 계층, 고객 요구사항 반영 로직을 기준으로 처리 (메서드 이름은 현실적인 로직의 이름을 붙이는 것이 관례이다.) 등록,회원검색,수정,삭제 등 Presentation 계층을 통해 메시지를 받고 DB와 협력하여 로직을 처리 Persistence Tire: 영속계층, 데이터에 대한 CRUD VO클..