Spring 개발단계 - 준비


(1)Spring Tool 설치


Spring Community http://spring.io/


>TOOLS 들어가서 다운로드


(2)톰캣 서버 가져오기


-기존 서버아닌 톰캣 9.0사용하였다.


(3) legacy project생성 

-MVC프로젝트선택



(4)JRE System Library 버전 변경


[ Java build path ]에서 JRE System Library 을 수정한다.




(5)web.xml파일 수정과 root-context.xml파일삭제를 한다.


-servlet 3.0 으로 변경

1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
</web-app>
 
cs


-해당부분삭제

]


: 부팅이 두개 되기때문에 



(6)

pom.xml 파일에서 springframework 버전을 최신버전(4.3.9.RELEASE)으로 다운로드 한다.

mysql도 추가한다.


1
2
3
4
5
6
7
<!-- mysql -->
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.39</version>
</dependency>
cs

(7)servlet-context.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
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.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">
 
    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
    
    <!-- Enables the Spring MVC @Controller programming model -->
    <mvc:annotation-driven />
 
    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <mvc:resources mapping="/resources/**" location="/resources/" />
 
    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>
    <context:component-scan base-package="com.jjdev.mvc" />
 
</beans>
 
cs


(8)마우스 우클릭 - [ run as ] - [ run on server] 실행확인





(9)Board , BoardDao 클래스 생성


(10)boardAdd.jsp 생성


(11)BoardController 클래스 생성후 BoardAdd()메소드 추가


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.jjdev.mvc;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestMapping;
 
@Controller
public class BoardController {
    @Autowired
    BoardDao boardDao;
    @RequestMapping(value="/boardAdd", method=RequestMethod.GET)
    public String boardAdd(){
        return "boardAdd";
    }
    @RequestMapping(value="/boardAdd", method=RequestMethod.POST)
    public String boardAdd(Board board){
        boardDao.insertBoard(board);
        return "redirect:/";
    }
    
    
}
 
cs


(12)Run on Server 후 주소창에 boardAdd 입력





(13)글작성 후 mysql에 데이터저장되었는지 확인.

+ Recent posts