mybatis 嵌套查詢子查詢column傳多個參數以下:html
備註:注意,相同顏色的單詞都是有關聯的。java
<resultMap id="blogResult" type="Blog">git
<association property="author" column="{id=author_id,likename=author_name}" javaType="Author" select="selectAuthor"/>github
</resultMap>sql
<select id="selectBlog" resultMap="blogResult" parameterType="java.lang.String">mybatis
SELECT author_id,author_name FROM BLOG WHERE ID = #{id} spa
</select>xml
<select id="selectAuthor" resultType="Author" parameterType="java.util.HashMap">htm
SELECT * FROM AUTHOR WHERE 1=1blog
<if test="id != null and id != '' ">
and ID = #{id}
</if>
<if test="likename != null and likename != '' ">
and name like CONCAT('%',#{likename},'%')
</if>
</select>
參考網址: http://mybatis.github.io/mybatis-3/zh/sqlmap-xml.html#Result_Maps