代码如下,红色部分为关键代码。

 

注意parameterType要为java.util.HashMap

 

<resultMap >

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

</resultMap>

 

 

<select >

  SELECT * FROM AUTHOR WHERE 1=1

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

         and ID = #{id} 

  </if>

  <if test="likename != null and likename != '' ">

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

  </if>

 <if test="author_id!= null and author_id!= '' ">

         and id=#{author_id}

  </if>

</select>

相关文章: