[SPRING] Mapper XML File

Yuri Lee·2022년 12월 12일
0

스프링

목록 보기
11/13

정의

SQL Mapping XML file은 실행할 SQL 문을 정의해놓은 파일.
SQL 실행을 위해 Parameter Object를 받아오거나 SQL문 실행결과를 Result Object 에 자동 바인딩하는 기능 제공

요소 정의!!!

Mapper XML file에서 사용가능한 요소는 다음과 같다.

  • < select>
  • < insert>
  • < update>
  • < delete>
  • < sql> : 다른 구문에서 재사용하기 위한 SQL 조각
  • < resultMap> : 데이터베이스 결과 데이터를 객체에 매핑하는 방법을 정의
  • < cache> : 자신의 namespace 를 위한 캐시설정
  • < cache-ref> : 다른 namespace 의 캐시설정을 참조

namespace 란?

http://devyongsik.tistory.com/527 참고!

< resultMap> 사용법

http://devyongsik.tistory.com/527 참고!

<mapper namespace="com.tistory.devyongsik.mapper.DualMapper">
 
             <resultmap id="dualResultMap" type="DualDomain"> 
             //id:여기서지정, type:dto형태의 데이터담을 객체 
                           <result column="keyword" property="r" jdbctype="VARCHAR">
                          
             </result></resultmap>
 
 
             <select id="selectAll" resultmap="dualResultMap">
                            select 1 as keyword from dual
             </select>
 
</mapper>
profile
개발자 이유리

0개의 댓글