q2617426
无感五
采纳率100%
2019-03-18 17:14

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

5

以下是多表查询得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条回答

  • whb3299065 whb3299065 2年前

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

    点赞 评论 复制链接分享