zoukankan      html  css  js  c++  java
  • Springboot 2.3.5使用 Mybatis 实现关联查询

    代码

    1. 一对一
    <!--    -->
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
            "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <!--这里对应Maper接口类的命名空间-->
    <mapper namespace="com.xxxxxx.suddenlynlinelearningplatform.mapper.VideoCommentMaper">
    <!--  查询评论  -->
         <resultMap type="com.xxxxxx.suddenlynlinelearningplatform.entity.VideoComment" id="videoCommentInfo">
             <id property="id" column="id"/>
             <association property="student" column="student_id" select="findStudentById">
             </association>
             <association property="repliedStudent" column="replied_student_id" select="findStudentById">
             </association>
             <association property="videoCommentList" column="id" select="findByWhileClassVideoComments">
             </association>
             <association property="myLike" column="{id=id,param2=student_id}"  select="findMyIsLike">
             </association>
         </resultMap>
    <!--  一级评论  -->
        <select id="findByFirstLevelVideoComments" resultMap="videoCommentInfo">
            select * from `video_comments` where video_comment_id=0 and status = 1 and video_id=#{param1}
        </select>
    <!--    二级评论-->
        <select id="findByWhileClassVideoComments" resultMap="videoCommentInfo">
            select * from `video_comments` where status = 1 and video_comment_id=#{video_comment_id}
        </select>
    <!--    查询学生-->
        <select id="findStudentById" parameterType="int" resultType="com.xxxxxx.suddenlynlinelearningplatform.entity.VideoCommentStudent">
            select id,name,avatar_url,bewrite from `students` where id = #{id}
        </select>
    <!--    查询自己是否点赞了这个博客-->
        <select id="findMyIsLike" resultType="int">
            select count(1) from `video_comment_likes` where video_comment_id=#{id} and student_id=#{param2} limit 1
        </select>
    </mapper>
    
    如果觉得文章对您有帮助,希望您能 关注+推荐 哦
  • 相关阅读:
    android animation
    android手机屏幕分辨率 及 sp dip(dp) px 区别 及高中低分辨率时处理
    android ExpandableListView
    android ImageView 之 android:scaleTye=" "
    android popupwindow
    如何使用 TransactSQL 编写作业脚本(企业管理器)
    线程访问临界区的问题 实例,需解决
    企业信息化
    使用Installshield制作asp,asp.net应用的安装程序
    Linux 系统目录结构
  • 原文地址:https://www.cnblogs.com/xiaqiuchu/p/15182732.html
Copyright © 2011-2022 走看看