MyBatis-Plus 多表查询

MP提供了大量单表查询的方法,但是没有多表的操作,所以涉及到多表的查询时,需要我们自己实现

前面内容可以跳过,可通过目录跳到多表查询示例

思路1

因为MP是基于MyBatis实现,我们可以使用MyBatis的结果映射来做,下面是一个官网的例子

https://mybatis.org/mybatis-3/zh/sqlmap-xml.html#Result_Maps

结果映射

<!-- 非常复杂的语句 -->
<select id="selectBlogDetails" resultMap="detailedBlogResultMap">
  select
       B.id as blog_id,
       B.title as blog_title,
       B.author_id as blog_author_id,
       A.id as author_id,
       A.username as author_username,
       A.password as author_password,
       A.email as author_email,
       A.bio as author_bio,
       A.favourite_section as author_favourite_section,
       P.id as post_id,
       P.blog_id as post_blog_id,
       P.author_id as post_author_id,
       P.created_on as post_created_on,
       P.se

版权声明:本文为web18484626332原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。