*참조1 http://karismamun.tistory.com/21?category=693508 *참조2 http://karismamun.tistory.com/25?category=693508 *참조3 http://karismamun.tistory.com/26?category=693508
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" 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_2_5.xsd"> <!-- The definition of the Root Spring Container shared by all Servlets and Filters --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/root-context.xml</param-value> </context-param> <!-- Creates the Spring Container shared by all Servlets and Filters --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- Processes application requests --> <servlet> <servlet-name>appServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring/appServlet/servlet-context.xml classpath:mybatis.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>appServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" 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"> <!-- Root Context: defines shared resources visible to all other web components --> <!-- DB연결 설정 --> <bean id = "dataSource" class = "org.apache.commons.dbcp.BasicDataSource"> <property name = "driverClassName" value = "oracle.jdbc.driver.OracleDriver"></property> <property name = "url" value = "jdbc:oracle:thin:@Localhost:1521:xe"></property> <property name = "username" value = "hr"></property> <property name = "password" value = "javaclass"></property> </bean> <bean id = "sqlSessionFactory" class = "org.mybatis.spring.SqlSessionFactoryBean"> <property name = "dataSource" ref = "dataSource"></property> <property name = "mapperLocations" value = "classpath*:com/test/spring/mapper/*.xml"></property> </bean> <bean id = "sqlSessionTemplate" class = "org.mybatis.spring.SqlSessionTemplate"> <constructor-arg index = "0" ref = "sqlSessionFactory"></constructor-arg> </bean> </beans>
사진 출처 : http://terasolunaorg.github.io/guideline/1.0.1.RELEASE/en/Overview/SpringMVCOverview.html#id2
Spring프로젝트는 보통 java단에서 4개로 세분화됩니다. Controller와 Service, DAO, DTO(VO)입니다. 먼저 Controller는 jsp로부터 데이터를 받아오거나 넘겨주고 주소를 맵핑하는 역할을 합니다. Service는 Controller에서 받아 온 데이터를 가공하는 로직을 넣는 부분입니다. 여기서 가공된 데이터는 DAO로 넘겨지게 됩니다. DAO는 Data Access Object의 약자로 DB를 사용해 데이터를 조회하거나 조작하는 기능을 담당합니다. DAO(VO)는 Data Trasfer Obejct의 약자인데 보통 DB의 컬럼값을 맵핑하기 위해 사용되는 객체들의 집합소입니다. 각 계층간의 흐름으로 따지면
Controller ←→ Service ↔ DAO - DTO
위와 같이 된다고 할 수 있겠습니다.
프로젝트를 만들면 기본적으로 생성됩니다.
root-context에서 설정한 mapper경로에다가 만들어주면 됩니다.