`
y806839048
  • 浏览: 1132609 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

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">

  SELECT author_id,author_name FROM BLOG WHERE ID = #{id} 

</select>

 

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

  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>

</select>

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics