MyBatis Sample Project

  1. GlueMyBatis를 사용하기 위한 필요 요소
    1. DAO, SQLSession, SessionFactory 의 정의 (applicationContext.xml)
      예시 )
      
          <bean id="test-dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
              <property name="driverClassName" value="${sqlite.test-dataSource.driverClassName}"/>
              <property name="url" value="${sqlite.test-dataSource.url}"/>
              <property name="defaultAutoCommit" value="false"/>
              <property name="minIdle" value="0"/>
              <property name="maxTotal" value="-1"/>
              <property name="maxIdle" value="1000"/>
          </bean>
          <bean id="test-dao" class="com.poscoict.glueframework.dao.mybatis.GlueMybatisDao">
              <property name="sqlSession" ref="sqlSession" />
          </bean>
          <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
              <constructor-arg index="0" ref="sqlSessionFactory" />
          </bean>
          <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
              <property name="dataSource" ref="test-dataSource" />
              <property name="mapperLocations" value="classpath*:mybatis/mapper/*.xml" />
          </bean>
    2. SQL mapper

      • SqlSessionFactoryBean의 mapperLocations 으로 정의한 경로에 위치
    3. VO

      • mapper 에서 resultType으로 지정한 이름의 class. 각 SQL 의 결과를 담을 VO.
    4. Activity (GlueMybatisInsert/Modity/Delete activity)

      • AD(Activity Diagram) 안의 activity setting
        • sql-key : mapper 에서 정의 된 sql id를 입력
        • param-bindings : MyBatisParamName=httpParamName

          예)empno=EMPNO|ename=ENAME|sal=SAL

  2. Sample 사용법

    • 이전 sample-hello-jdbc 샘플에서 생성한 sample.db 를 확보. (SQLite_DB.java 또는 CreatDB.java 실행으로 얻어짐).
    • applicationContext.xml 에 test-dataSource 의 properties를 sample.db 위치에 맞게 수정
      1. 로컬에서 테스트

        • test.MyBatisDaoTest 또는 test.ServiceTest_sample11, ServiceTest_sample12 class 실행
      2. WAS 로 테스트

        • build.xml 을 실행하여 WAR로 build 및 deploy 후
        • 브라우저로 http://WAS ip:WAS port/sample-mybatis/ 접속
        • reuse activity 사용은 sample11-service 를 이용. parameterType 은 map 만 가능
        • custom activity 사용은 sample12-service 를 이용. GlueMyBatisDao 를 직접 호출하며 VO Class 를 parameterType 으로 지정 가능
        • 부서 입력 칸에 "10" 을 입력 후 "조회" 버튼 클릭
        • 같은 방법으로 입력/수정/삭제 실행 테스트
          sample.jsp