1、复杂类型查询
<resultMap id=”get-product-result” class=”com.ibatis.example.Product”> <result property=”id” column=”PRD_ID”/> <result property=”description” column=”PRD_DESCRIPTION”/> <result property=”category” column=”PRD_CAT_ID” select=”getCategory”/> </resultMap> <resultMap id=”get-category-result” class=”com.ibatis.example.Category”> <result property=”id” column=”CAT_ID”/> <result property=”description” column=”CAT_DESCRIPTION”/> </resultMap> <statement id=”getProduct” parameterClass=”int” resultMap=”get-product-result”> select * from PRODUCT where PRD_ID = #value# </statement> <statement id=”getCategory” parameterClass=”int” resultMap=”get-category-result”> select * from CATEGORY where CAT_ID = #value# </statement>
2、联合查询
<resultMap id=”get-product-result” class=”com.ibatis.example.Product”> <result property=”id” column=”PRD_ID”/> <result property=”description” column=”PRD_DESCRIPTION”/> <result property=”category.id” column=”CAT_ID” /> <result property=”category.description” column=”CAT_DESCRIPTION” /> </resultMap> <statement id=”getProduct” parameterClass=”int” resultMap=”get-product-result”> select * from PRODUCT, CATEGORY where PRD_CAT_ID=CAT_ID and PRD_ID = #value# </statement>