MyBatis——实现级联表查询(一对一,一对多)

一对一:

MyBatis中使用association标签来解决一对一的关联查询,association标签可用的属性如下:

  • property:对象属性的名称
  • javaType:对象属性的类型
  • column:所对应的外键字段名称
  • select:使用另一个查询封装的结果

一对多:

property:属性名称
column:外键列
javaType:类型(可以是自己的实体类)
select:关联的查询语句
collection:一对多的标签
property:属性名称
column:外键列

MyBatis中使用collection标签来解决一对多的关联查询,ofType属性指定集合中元素的对象类型。

 

审核管理信息
private static final long serialVersionUID = 1L;
private String projectId;     // 项目编号
private Integer examineType;      // 审核类型
private String examinePerson;     // 审核人
private Date examineTime;     // 审核时间
private String modifyOpinions;    // 修改意见
private Integer auditConclusion;      // 审核结论
private Integer isReview;     // 是否复审(yes_no)
private Integer totalScore;       // 总得分
private Integer subjectLevel;     // 主体级别
private List<RateAuditScoreDetail> rateAuditScoreDetails;
private List<RateExamineObj> rateExamineObjList=new ArrayList<>();
private RateExamineObjType rateExamineObjType;
private RateSignPromise rateSignPromise;

 

审核得分明细(RateAuditScoreDetail
private static final long serialVersionUID = 1L;
private String examineManagerId;      // 审核管理编号
private String auditProjectId;    // 考核项编号
private Integer examineGoal;      // 考核项得分

做映射

<resultMap type="AuditManagerInfo" id="AuditManagerInfoBig">
   <id column="project_id" property="projectId"/>
   <result column="examine_type" property="examineType"/>
   <result column="examine_person" property="examinePerson"/>
   <result column="examine_time" property="examineTime"/>
   <result column="modify_opinions" property="modifyOpinions"/>
   <result column="audit_conclusion" property="auditConclusion"/>
   <result column="is_review" property="isReview"/>
   <result column="total_score" property="totalScore"/>
   <result column="subject_level" property="subjectLevel"/>
   <!-- 考察项 -->
   <collection  property="rateExamineObjList" javaType="java.util.List" ofType="com.dagongsoft.modules.auditManagement.entity.RateExamineObj">
      <id column="examine_obj_type_id" property="examineObjTypeId"/>
      <result column="examine_obj_name" property="examineObjName"/>
      <result column="score_weight" property="scoreWeight"/>
      <result column="enable_state" property="enableState"/>
      <result column="sort" property="sort"/>
      <result column="examineGoal" property="examineGoal"/>
   </collection>
</resultMap>

关联实体类:

<resultMap type="RateProjectBasicInfo" id="rateProjectBasicInfoResultMap">
   <id column="ID" property="id" />
   <result column="PROJECT_NAME" property="projectName" />
   <result column="COMPANY_ID" property="companyId" />
   <result column="INDUSTRY_NUM" property="industryNum" />
   <result column="PROJECT_TYPE" property="projectType"/>
   <result column="PROJECT_SOURCE" property="projectSource"/>
   <result column="PROJECT_TIME" property="projectTime"/>
   <result column="CURRENT_NODE_ID" property="currentNodeId"/>
   <result column="PROJECT_STATE" property="projectState"/>
   <!--注意:这种方式javaType必须指定,表示rateTaskInfo的类型是RateTaskInfo,否则会报错 -->
   <association property="rateTaskInfo" javaType="RateTaskInfo">
      <!-- RateTaskInfo自身的属性与数据库字段的映射 -->
      <id property="handlePersonId" column="HANDLE_PERSON_ID"/>
      <result property="submitStatus" column="SUBMIT_STATUS"/>
      <result property="taskIsComplete" column="TASK_IS_COMPLETE"/>
   </association>
</resultMap>

 

 

 

 

 

 

相关推荐

  1. MyBatis——实现查询一对一

    2024-03-28 05:22:09       18 阅读
  2. mybatis一对一,字段重复

    2024-03-28 05:22:09       12 阅读
  3. Mybatis查询

    2024-03-28 05:22:09       34 阅读
  4. mybatis 查询

    2024-03-28 05:22:09       8 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-28 05:22:09       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-28 05:22:09       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-28 05:22:09       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-28 05:22:09       20 阅读

热门阅读

  1. 设计模式-----观察者模式

    2024-03-28 05:22:09       20 阅读
  2. flutter弹框

    2024-03-28 05:22:09       16 阅读
  3. SQL语言入门注意

    2024-03-28 05:22:09       19 阅读
  4. Redis中的缓存雪崩、缓存击穿、缓存穿透问题

    2024-03-28 05:22:09       21 阅读
  5. PTA------ 敲笨钟

    2024-03-28 05:22:09       22 阅读
  6. Filter和Intercepter中怎么获取Spring托管的bean对象

    2024-03-28 05:22:09       17 阅读
  7. yolov8 在训练好的模型基础上切换为中文标签

    2024-03-28 05:22:09       21 阅读
  8. 面向对象编程(一)

    2024-03-28 05:22:09       19 阅读
  9. 实现阻塞队列

    2024-03-28 05:22:09       18 阅读