clean과 서버 재실행은 개필수! ㄹㅇㅈㅂㅜㅜ
기초적인 설정들은 ppt에 있다.
요약하자면 maven project를 만들고
- pom.xml 에서 저장하여 각 라이브러리들을 추가해준다. <dependencies>태그 안의 내용들이 라이브러리 추가해주는것
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.douzone</groupId> <artifactId>hellospring</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <properties> <org.springframework-version>4.2.1.RELEASE</org.springframework-version> </properties> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${org.springframework-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${org.springframework-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${org.springframework-version}</version> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>3.2.1</version> <configuration> <warSourceDirectory>webapp</warSourceDirectory> </configuration> </plugin> </plugins> </build> </project> | cs |
- web.xml에 dispatchservlet에 대한 서블릿 매핑을 추가
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 | <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>hellospring</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app> | cs |
- WEB-INF 밑views 폴더 생성후 spring-servle.xml 에 컨트롤러로 보내준다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:annotation-config /> <context:component-scan base-package="com.douzone.hellospring.controller" /> </beans> | cs |
- HelloController를 @Controller해준후 RequestMapping을 "/hello"로해준다. return에 보여주고자할 페이지를 보여준다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | package com.douzone.hellospring.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class HelloController { @RequestMapping("/hello") public String hello() { return "/WEB-INF/views/hello.jsp"; } //실행시 리턴 } | cs |
- 추가적으로 해준 것들
1) pom.xml 구성
2) DispatcherServlet 등록( web.xml )
3) 서블릿 애플리케이션 컨텍스트 설정 (spring-servlet.xml)
4) Controller 작성
- 생략된 것들
1) 서블릿 작성
2) 파라미터 처리 request.getParameter()
3) forwarding
mvc순서
1. DispatcherServlet
2. Handler Mapping
3. Controller
4. ModelAndView
5. View Resolver
6. DispatcherServlet->View
다음 정리 - 실행 순서 및 코드에서 알아보기
728x90
'풀스택 > Spring' 카테고리의 다른 글
spring에서의 예외처리 (0) | 2019.02.23 |
---|---|
ViewResolver 설정 (0) | 2019.02.23 |
spring html, css적용 안될때 (0) | 2019.02.23 |
ㅁ (0) | 2019.02.19 |
spring 예제 emaillist->emaillist3 (0) | 2019.02.19 |
댓글