无感五 2019-03-18 17:14 采纳率: 50%
浏览 3036
已采纳

SpringBoot+MybatisPlus2.x版本里面多表查询需要写XML吗

以下是多表查询得XML写法,请问一下如果使用MybatisPlus得话,应该怎么简化他呢,不直接使用XML来实现

<resultMap id="BaseResultMap" type="com.tedu.pojo.admin.Problem" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="video_id" property="videoId" jdbcType="VARCHAR" />
    <result column="from_user_id" property="fromUserId" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="comment" property="comment" jdbcType="LONGVARCHAR" />
    <result column="face_image" property="faceImage" jdbcType="VARCHAR" />
    <result column="nickname" property="nickname" jdbcType="VARCHAR" />
    <result column="toNickname" property="toNickname" jdbcType="VARCHAR" />
  </resultMap>


  <select id="queryComments" resultMap="BaseResultMap" parameterType="String">
    select c.*,u.face_image as face_image,u.nickname,tu.nickname as toNickname 
    from comments c 
    left join users u on c.from_user_id = u.id
    left join users tu on c.to_user_id = tu.id
    where c.video_id = #{videoId} order by c.create_time desc
  </select>
  • 写回答

1条回答 默认 最新

  • huibinwei 2019-03-18 19:34
    关注

    多表查询你局老老实实写sql就行了,想不直接写XML也可以,,,直接用Mapper吧sql写到注解上,写sql是为了方便维护

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?