티스토리 뷰

Java/Spring

[MyBatis]underscore 문제 해결

berryberries 2023. 5. 3. 03:12

db컬럼명에 (_)underscore가 있을경우 문제가 생길 수 있다. 

해결 방법은 총 3가지가 있다

 

1. SQL Alias 를 이용

<select id="selectAll" resultType="dto.Underscore"> 
		SELECT 
			user_id AS userId
			, user_pw AS userPw 
		FROM underscore
 		ORDER BY user_id 
</select>

컬럼명에 alias를 설정해서 적어주는 방식

 

2.resultMap 태그를 이용

<resultMap type="dto.Underscore" id="MapUnderscore">
 		<result column="user_id" property="userId" />
 		<result column="user_pw" property="userPw" />
</resultMap> 

<select id="selectAll" resultMap="MapUnderscore"> 
		SELECT 
 			user_id 
 			, user_pw 
 		FROM underscore 
 		ORDER BY user_id 
 </select>

 

3.Configuration설정의 mapUnderscoreToCamelCase 설정값으로 해결

'Java > Spring' 카테고리의 다른 글

[spring] Spring Security  (0) 2023.10.23
[MyBatis]config.xml  (0) 2023.05.03
[MyBatis]ConnectionFactory  (0) 2023.05.03
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/05   »
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
글 보관함