一对一:
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>










