티스토리 뷰
Spring mvc framework
model -view -controller구조를 제공하며, web application을 개발하는 framework이다.
Model - POJO라는 plain old java object라는 구조로 이뤄져있으며, 애플리케이션 데이터를 캡슐화 하는 역할을 한다.
View - 모델 데이터를 랜더링한 html output을 보여준다.
Controller - 1. 사용자의 요청을 처리 2. 적절한 모델을 바인딩하고 view에게 건네준다
Spring MVC Overview
이 구조가 전체적인 구조이다.
Dispatcher servlet
프론트 컨트롤러 역할을 수행한다.
애플리케이션으로 들어오는 모든 요청을 받게 된다. 요청을 적절한 핸들러에게 전달하는 역할을 한다.
Handler Mapping
요청에 따른 적절한 컨트롤러를 찾아서 준다.
매핑정보는 xml or 애노테이션을 사용한다.
Controller
비즈니스나 서비스 클래스를 불러서, 요청을 처리한다.
Output이 뷰로 전송될 모델객체에 전송된다.
View Resolver
Controller가 전해준 logical name을 기준으로 구체적인 뷰를 찾아준다.
View
jsp, html, xml등등의 구체적인 뷰 파일이다.
MVC Project Structure
Java Resources 안에 controllers, dao, model, ,service 파일등이 있다.
webapp은 전체적으로 war파일로 패키징된다.
java Resources 파일들이 컴파일되어서, classes에 위치한다.
spring 안에는 각종 설정파일들이 있다
ex) dao-context.xml, service-context.xml, servlet-context.xml
views 파일에는 view들이 위치해있다.
pom.xml에는 maven 설정파일들이 있다.
각종 설정파일
maven 설정 ==> POM.xml
web deployment descriptor(웹 배포 기술자- servlet이 어떤 URL과 매핑되는가 ) ==> Web.xml
Spring MVC 설정 ==> root-context.xml, servlet-context.xml,dao-context.xml, serviece-context.xml
Maven 설정=> pom.xml
<groupId> </groupId>
<artifactId> </artifactId>
<packaging>war</packaging>
<version> </version>
groupId, artifactId, version 이 세개가 프로젝트의 식별자가 된다
packaging이 war이니까 패키징이 war파일로 된다.
<dependency>
<groupId>org.springFramework</groupId>
<artifactId>spring=webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
스프링 mvc이기에 이 dependency가 무조건 들어가야 한다.
Web deployment descriptor => web.xml 웹 배포 기술자
DispatcherServlet
스프링컨테이너를 만든다. 이 스프링컨테이너 안에 컨트롤러와 handlerMapping, ViewResolver의 bean이 들어가 있다.
ContextLoadListener
DispatcherServlet에서 공유되는 bean들이 ContextLoadListener에 들어간다.
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring.root-cotext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.sevlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<param-value>가 설정파일들이 실제 저장되어있는 위치
Spring MVC 설정
1. root-context.xml - 모두 공유되는 서블릿과 필터에 적용된다.
ContextLoaderListener에 의해 root-context.xml파일이 올려진다.
2. servlet-context.xml
DispatcherSevlet에 의해 올려진다.
servlet-context.xml
1. annotation-driven - 스프링에게 애노테이션 사용할거라는 정보를 주는
2. resource mapping - 정적자원이 어떤 파일인지, 어디에 저장되어있는지
3. Bean InternalResourceViewResolver - jsp파일을 쉽게 찾을 수 있도록 prefix, suffix를 설정할 수 있다.
4. context: component-scan -컨테이너가 컨트롤러를 쉽게 찾을 수 있도록 기본 패키지를 설정
'web웹프로그래밍' 카테고리의 다른 글
Html 핵심 (0) | 2022.02.02 |
---|---|
1. WAS, Servlet 개념, 정리 (0) | 2022.01.30 |
백엔드 mvc 패턴) 컨트롤러 구현 controller (0) | 2021.11.16 |
백엔드 model, DAO구현 (0) | 2021.11.16 |
web 구현환경 설정하기 (0) | 2021.11.11 |
- Total
- Today
- Yesterday
- laravel
- 자바
- 모델링
- 스프링
- 유스케이스
- 이클립스
- eclipse
- 백엔드
- 코드업
- sql
- sourcetree
- 객체지향
- 레이아웃
- web
- java
- 안드로이드
- Spring
- UML
- 파이썬
- 코딩
- 객체지향모델링
- 깃
- 자바기초
- 코드업기초
- 다이어그램
- set
- JPA
- 기초100제
- 파이썬기초
- 개인프로젝트
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |