본문 바로가기
비트 장기/설치방법들

srping mvc를 위한 환경설정

by woohyun22 2018. 8. 16.

자바

알고리즘

로직

다형성



srping의 3요소


di   장기 클래스에 인공지능을 넣는 것을 주입 장기 클래스에 인공지능을 넣지 않으면 실행 안됨 의존적이다. 

의존 d 주입 i



ioc     제어의 역전 나는 틀만 만들어 주고 사용자가 제어하는 것 ex) 울어라 했을때 내가 울리는게 아니라 사용자가 울리는 것임.

   ex)  웹에 대한 컨트롤을 사용자가 한다. 장기 바둑중에 고르라고했는데 고           르는것은 상대방이 함

   ex)  tomcat도 제어의 역전에 해당함.

 

aop

관점지향 프로그램

프로그램 시작

crud

프로그램 끝


중간에 들어가는 코드를 인수전달이 가능하다면 익명개체 중간에 삽입되는 코드


   


게임


init(){

초기화

}


update(){

초기화

}


index-> design

di ->     java

model   view



model      model

view        control된 결과를 보여주고있다 view(비지니스 로직)

control     제어(프레젠테이션 로직)



mvc파일을 분리시켜서 작업하자



1. spring mvc 환경 구축하기


maven 선택 -> create check해제 -> spring01 x2 finish -> spring 속성 -> project facets -> dynamic web module와 java의 버전 확인


2. java버전및 web 버전 설정


java프로젝트 폴더 위치 속성창 resource에서 주소확인 .settings -> C:\Users\user\eclipse-workspace\spring01\.settings


-> org.eclipse.jdt.core.prefs라는 파일을 메모장으로 연다 -> 1.5를 1.8로 바꾼후 저장

-> org.eclipse.wst.common.project.facet.core 1.5를 1.8 2.3을 3.0으로 바꾼후 저장

-> 

프로젝트 클릭후 alt f5 포스 체크 후 확인 -> 버전확인 -> runtime apply ->apply close


3. xml 들어가서 복붙 url밑으로 지우고 /build까지


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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<properties>
<spring.version>4.0.1.RELEASE</spring.version>
</properties>
 
<repositories>
<repository>
<id>codelds</id>
<url>https://code.lds.org/nexus/content/groups/main-repo</url>
</repository>
</repositories>
 
<dependencies>
 
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
 
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
 
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
</dependency>
 
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
 
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.0.RELEASE</version>
</dependency>
 
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
 
</dependencies>
 
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
 
cs

넣기


4. 프로젝트 src -> main -> webapp -> web-inf -> web.xml 더블클릭 밑에 source탭 열기 후 싹다 지우기


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
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>Archetype Created Web Application</display-name>
 
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
 
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
 
<!--한글 설정-->
 
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app> 
cs


넣기


5 프로젝트 src -> main -> webapp -> web-inf에서 new 이름 xml밑에 XML file next 파일명 dispatcher-servlet 입력 finish


xml 들어가서 source 지우고 


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"?>
 
<beans xmlns ="http://www.springframework.org/schema/beans"
xmlns:context ="http://www.springframework.org/schema/context"
xmlns:mvc ="http://www.springframework.org/schema/mvc"
xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"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
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
 
<context:component-scan base-package="Pack01" />
 
<mvc:annotation-driven/>
<mvc:default-servlet-handler/>
 
<mvc:view-resolvers>
<mvc:jsp prefix="/WEB-INF/Views/"/>
</mvc:view-resolvers>
 
</beans>
 
cs


넣고 alt f5 오류안없어질 경우 포스 다 체크해주기


6 index 에 넣고 실행


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.*, java.text.*"%>
 
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
 
<head>
<title>메인 페이지</title>
</head>
<body>
<%=new Date()%>
<h2>Hello World</h2>
 
</body>
 
cs


7 src -> main 에서 new 폴더 ->폴더안에서 new java밑에 class next package이름 Pack01 name은 Tiger static void check안함 finish


Tiger 위에 @con ctrl space -> controller


1
2
3
import org.springframework.stereotype.Controller;
 
@Controller
cs


springframework

이게 spring쓰고있따는거임


@req ctrl space @RequestMapping


1
2
3
4
5
6
7
8
9
10
11
12
13
14
package Pack01;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
 
@Controller
public class Tiger {
    @RequestMapping("t1")
    String fnuc() {
        System.out.println("들어왔음");
        return null;
    }
}
 

cs


이런형태



spring만약 안될경우에는


C:\Users\user\.m2\repository 

에있는 파일들을 날려버리고 다시 atl f5하자


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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>spring01</groupId>
    <artifactId>spring01</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring01 Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <properties>
        <spring.version>4.0.1.RELEASE</spring.version>
    </properties>
 
    <repositories>
        <repository>
            <id>codelds</id>
            <url>https://code.lds.org/nexus/content/groups/main-repo</url> -여기서 오라클
        </repository>
    </repositories>
 
    <dependencies>
 
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.3</version>
        </dependency>
 
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
            <scope>test</scope>
        </dependency>
 
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.2</version>
        </dependency>
 
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
        </dependency>
 
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.1.0.RELEASE</version>
        </dependency>
 
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
 
    </dependencies>
 
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
 
cs



두번째





pom.xml 맨 밑부분 source 자바 버전을 맞춰줘야된다. 위에 artifactId안에 이름이 같아야된다. spring1



이 maven 소스들 들고오는 근본 주소 http://repo.maven.apache.org/maven2/ 


예시 http://repo.maven.apache.org/maven2/javax/servlet/jsp/javax.servlet.jsp-api/2.2.1/


     <dependency>

<groupId>javax.servlet.jsp</groupId>

<artifactId>jsp-api</artifactId>

<version>2.2</version>

</dependency>




web.xml


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
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>Archetype Created Web Application</display-name>
 위에는 그냥 필요한것
<servlet>자바 없었을때 html직접만듬
<servlet-name>dispatcher</servlet-name> 이 이름을 바꾸게된다 web-inf에 있는 dispatcher xml명을 바꾸어줘야된다.
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
 
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
 
<!--한글 설정-->
 
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app
cs




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"?>
 
<beans xmlns ="http://www.springframework.org/schema/beans"
xmlns:context ="http://www.springframework.org/schema/context"
xmlns:mvc ="http://www.springframework.org/schema/mvc"
xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"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
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
 
<context:component-scan base-package="Pack01" />
 패키지 이름을 바꾸면 이것까지 바꿔줘야됨.자바파일 찾을때 pack01에서 찾아라(대소문자구분 확실하게)
<mvc:annotation-driven/>
<mvc:default-servlet-handler/>
 
<mvc:view-resolvers>
<mvc:jsp prefix="/WEB-INF/Views/"/>
jsp파일을 여기서 찾아라 경로지정하는 것임.
</mvc:view-resolvers>
 
</beans>
 
cs


728x90

댓글