전체 구성
pom.xml
root-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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42  | <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"     xmlns:aop="http://www.springframework.org/schema/aop"     xmlns:jdbc="http://www.springframework.org/schema/jdbc"     xmlns:context="http://www.springframework.org/schema/context"     xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd         http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.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-4.3.xsd         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">     <!-- Root Context: defines shared resources visible to all other web components -->         <!--  기본 적으로 dataSource를 통해 DB와 연결 될 수 있도록 연결 -->         <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">             <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"></property>             <property name="url" value="jdbc:mysql://localhost:3306/test?serverTimezone=Asia/Seoul"></property>             <property name="username" value="steve"></property>             <property name="password" value="steve"></property>         </bean>         <!--  dataSource를 mybatis와 같이 쓸 수 있도록 설정.                    그리고 그 경로인 데이터사용될 mybatis-config.xml에 저장되어있는 데이터 사용할 수 있도록 파일 경로설정 -->         <bean id="sqlSession" class="org.mybatis.spring.SqlSessionFactoryBean">             <property name="dataSource" ref="dataSource" />             <property name="configLocation" value="classpath:mybatis-config.xml" />         </bean>         <!-- 어노테이션에 사용될 sqlSession 설정 -->         <bean class="org.mybatis.spring.SqlSessionTemplate">             <constructor-arg ref="sqlSession" />         </bean> </beans>  | cs | 
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 27 28 29 30 31 32 33 34  | <?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframework.org/schema/mvc"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xmlns:beans="http://www.springframework.org/schema/beans"     xmlns:context="http://www.springframework.org/schema/context"     xmlns:aop="http://www.springframework.org/schema/aop"     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         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">     <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->     <!-- Enables the Spring MVC @Controller programming model -->     <annotation-driven />     <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->     <resources mapping="/resources/**" location="/resources/" />     <resources mapping="/css/**" location="/resources/css/" />     <resources mapping="/js/**" location="/resources/js/" />     <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->     <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">         <beans:property name="prefix" value="/WEB-INF/views/" />         <beans:property name="suffix" value=".jsp" />         <beans:property name="contentType" value="text/html; charset=UTF-8"/>     </beans:bean>     <context:component-scan base-package="com.steve.test" /> </beans:beans>  | cs | 
mybatis-confg.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19  | <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration>     <settings>         <setting name="jdbcTypeForNull" value="NULL"/>     </settings>     <typeAliases>                 <typeAlias type="com.steve.test.member.vo.MemberVo" alias="Member"/>     </typeAliases>     <mappers>          <mapper resource="mappers/member.xml"/>     </mappers> </configuration>  | cs | 
mapper.xml
1 2 3 4 5 6 7 8 9 10 11  | <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="Member"> <select id="memberSelect" parameterType="String" resultType="Member"> select memberId,memberPw from member where memberId= #{memberId}; </select> </mapper>  | cs | 
'Frameworks > Spring' 카테고리의 다른 글
| jstl 세자리 콤마(금액 넣을 때) (0) | 2019.04.08 | 
|---|