본문 바로가기

공부/SpringBoot & Spring

mybatis mapper resultMap

반응형

mybatis mapper를 사용할때 여러개의 테이블을 join하기 위해서

resultMap을 많이 사용한다.

 

	<resultMap type="FeedDTO" id="FeedDTO">
	    <result column="user_code_no" property="userCodeNo"/>
	    <result column="feed_code" property="feedCode"/>
	    <result column="feed_text" property="feedtext"/>
	    <collection property="FollowDTO" resultMap="FollowDTO"/>
	</resultMap>

이런 느낌으로!

 

근데 만약 resultMap으로 해줘야되는 테이블이 많다면?

하나하나 result column부터 해서 property까지 엄청 적어줘야한다..!

 

너무 힘들고 시작전부터 막막하다.

 

그러다 우연히 찾게 된 autoMapping!

 

	<resultMap type="FeedDTO" id="FeedDTO" autoMapping="true">
	</resultMap>

이렇게 autoMapping="true"를 넣어주면 자동 매핑된다..

 

너무나 유용하다 끝!

반응형