DEV
[mybatis] include refid - 반복되는 쿼리 묶기
veee2
2022. 5. 13. 16:36
refid(reference id)는 반복되는 쿼리를 미리 작성해 놓고 재활용 할 수 있게 해준다.
작성 예시
<mapper>
<sql id="a">
SELECT *
FROM TABLE
</sql>
<sql id="b">
SELECT *
FROM TABLE
WHERE ${param1}
</sql>
<select id="getListA" resultType="hashmap">
<include refid="a" />
WHERE filed = #{value}
</select>
<select id="getListB" resultType="hashmap">
<include refid="b">
<property name="param1" value="value">
</include>
WHERE filed = #{value}
</select>
</mapper>
쿼리 실행 결과
1
2
3
|
SELECT *
FROM TABLE
WHERE filed = #{value}
|