ABOUT ME

-

오늘 방문자
-
어제 방문자
-
전체
-
  • Mybatis - mapUnderscoreToCamelCase
    Spring 2018. 7. 30. 20:25

    데이터베이스의 전통적인 네이밍 방식은 언더스코어표기법이고

    JAVA표준인 네이밍은 카멜표기법이다


    그럼 개발을 할때 난감한 상황이 온다..


    테이블 컬럼명과 vo의 데이터명이 다르기 때문에 맵핑이안된다!


    그럼 어떻게 하냐


    Mybatis에서 mapUnderscoreToCamelCase를 설정해 주면 가능하다


    ex)

      USER_NAME (DB) - > userName(VO) 이렇게 자동으로 맵핑이된다









    프로젝트구조








    세팅법


    context-mybatis.xml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <?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="mapUnderscoreToCamelCase" value="true"/>
        </settings>
    </configuration>
        
     
    cs





    context-mapper.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
    <?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:context="http://www.springframework.org/schema/context"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:aop="http://www.springframework.org/schema/aop"
        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/aop 
                            http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
                            http://www.springframework.org/schema/tx 
                            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                            ">
     
     <!-- name은 sqlSession빈에서 사용할 이름이다, ref는  context-datasource.xml에서 정의한 빈을 참조
             value는 SQL문이 위치할 장소
     -->
     
        <bean id="sqlSession" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="dataSource" />
            <property name="mapperLocations" value="classpath:/sqlmap/*.xml" />
            <property name="configLocation" value="classpath:/spring/context-mybatis.xml"/>
        </bean>
         
        <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate" destroy-method="clearCache">
            <constructor-arg index="0" ref="sqlSession"/>
        </bean
        
        <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
                <property name="dataSource" ref="dataSource"/>
        </bean>
            
    </beans>
     
     
     
    cs




    'Spring' 카테고리의 다른 글

    Swagger란?  (0) 2018.09.17
    데이터베이스 연동  (0) 2018.09.04
    Spring Security 중복로그인 막기  (0) 2018.09.04
    Spring Security 태그  (0) 2018.09.04
    @Transactional 세팅 및 사용법  (0) 2018.07.29

    댓글

Designed by Tistory.