refid(reference id )는 반복되는 쿼리를 미리 작성해 놓고 재활용 할 수 있게 해준다.
반복할 쿼리 선언: <sql id =" ">
선언한 쿼리 사용: <include refid="">
변수 사용방법:<property name="">
작성 예시
<mapper>
<sql id ="test_a">
select *
from table
</sql>
<sql id = "test_b">
select *
from table
where ${param}
</sql>
<select id ="getListA" resultType="hashmap">
<include refid="test_a"/>
where filed=#{value}
</select>
<select id = "getListB" resultType="hashmap">
<include refid = "test_b">
<property name = "param1" value="value">
</include>
where filed = #{value}
</select>
</mapper>
getListA, getListB 의 출력 결과
SELECT *
FROM TABLE
WHERE filed = #{value}
'두번째 프로젝트 이야기' 카테고리의 다른 글
특수문자를 태그로 변경 (0) | 2023.10.25 |
---|---|
정규표현식-시분초 (0) | 2023.10.23 |
이벤트 바인딩 (0) | 2023.10.05 |
Map 정리 (0) | 2023.09.26 |
SUBSTR 정리 (0) | 2023.09.26 |