-
Mybatis - mapUnderscoreToCamelCaseSpring 2018. 7. 30. 20:25
데이터베이스의 전통적인 네이밍 방식은 언더스코어표기법이고
JAVA표준인 네이밍은 카멜표기법이다
그럼 개발을 할때 난감한 상황이 온다..
테이블 컬럼명과 vo의 데이터명이 다르기 때문에 맵핑이안된다!
그럼 어떻게 하냐
Mybatis에서 mapUnderscoreToCamelCase를 설정해 주면 가능하다
ex)
USER_NAME (DB) - > userName(VO) 이렇게 자동으로 맵핑이된다
프로젝트구조
세팅법
context-mybatis.xml
123456789101112<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configurationPUBLIC "-//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
123456789101112131415161718192021222324252627282930313233343536373839<?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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-2.0.xsdhttp://www.springframework.org/schema/txhttp://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