1. 程式人生 > >mybatis關聯查詢傳參

mybatis關聯查詢傳參

mybatis 巢狀查詢子查詢column傳多個引數如下:

1、圖解

2、程式碼示例

備註:注意,相同顏色的單詞都是有關聯的。

<resultMap id="blogResult" type="Blog">

  <association property="author" column="{id=author_id,likename=author_name}" javaType="Author" select="selectAuthor"/>

</resultMap>

<select id="selectBlog" resultMap="blogResult" parameterType="java.lang.String">

  SELECTauthor_id,author_nameFROM BLOG WHERE ID = #{id} 

</select>

<select id="selectAuthor" resultType="Author" parameterType="java.util.HashMap">

  SELECT * FROM AUTHOR WHERE 1=1

  <if test="id!= null andid!= '' ">

         and ID = #{id} 

  </if>

  <if test="likename!= null andlikename

!= '' ">

         and name like CONCAT('%',#{likename},'%')

  </if>

</select>