Spring Boot+mybatis多表链接查询,重复外键
Posted wqjbook
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring Boot+mybatis多表链接查询,重复外键相关的知识,希望对你有一定的参考价值。
<resultMap id="recMap" type="com.winter.entity.work.RecruitEntity">
<id column="rec_id" property="recId"/>
<result column="rec_name" property="recName"/>
<result column="rec_number" property="recNumber"/>
<result column="education_id" property="educationId"/>
<result column="rec_year" property="recYear"/>
<result column="rec_describe" property="recDescribe"/>
<result column="acceptance_of_disability" property="acceptanceOfDisability"/>
<result column="contacts" property="contacts"/>
<result column="contacts_number" property="contactsNumber"/>
<result column="contacts_email" property="contactsEmail"/>
<result column="pec_time" property="pecTime"/>
<result column="detailed_address" property="detailedAddress"/>
<association property="positionEntity" javaType="com.winter.entity.work.PositionEntity">
<id column="pos_id" property="posId"/>
<result column="pos_name" property="posName"/>
</association>
<association property="salaryEntity" javaType="com.winter.entity.work.SalaryEntity">
<id column="sal_id" property="salId"/>
<result column="sal_name" property="salName"/>
</association>
<association column="rec_province" property="recProvince" javaType="com.winter.entity.RegionEntity">
<id column="reg_id" property="regId"/>
<result column="reg_name" property="regName"/>
<result column="pid" property="pid"/>
</association>
<association column="rec__city" property="recCity" javaType="com.winter.entity.RegionEntity">
<id column="reg_id" property="regId"/>
<result column="reg_name" property="regName"/>
<result column="pid" property="pid"/>
<result column="rec_type" property="recType"/>
</association>
<association column="rec_town" property="recTown" javaType="com.winter.entity.RegionEntity">
<id column="reg_id" property="regId"/>
<result column="reg_name" property="regName"/>
</association>
<association property="companyEntity" javaType="com.winter.entity.work.CompanyEntity">
<id column="com_id" property="comId"/>
<result column="com_name" property="comName"/>
</association>
<collection property="resumeEntities" ofType="com.winter.entity.work.ResumeEntity">
<id column="res_id" property="resId"/>
<result column="res_name" property="resName"/>
</collection>
<collection property="treatmentEntities" ofType="com.winter.entity.work.TreatmentEntity">
<id column="tre_id" property="treId"/>
<result column="tre_name" property="treName"/>
</collection>
</resultMap>
<select id="queryRecAll" resultMap="recMap" parameterType="com.winter.util.ConditionUtil">
select
rec.*,
pos.pos_id,
pos.pos_name,
sal.sal_id,
sal.sal_name,
reg1.reg_id,
reg1.reg_name,
reg2.reg_id,
reg2.reg_name,
reg3.reg_id,
reg3.reg_name,
com.com_id,
com.com_name,
res.res_id,
res.title,
tre.tre_id,
tre.tre_name
from cw_recruit rec
left outer join cw_position as pos on pos.pos_id = rec.pos_id
left outer join cw_salary as sal on sal.sal_id = rec.sal_id
left outer join cw_region as reg1 on reg1.reg_id = rec.rec_province
left outer join cw_region as reg2 on reg2.reg_id = rec.rec_city
left outer join cw_region as reg3 on reg3.reg_id = rec.rec_town
left outer join cw_company as com on com.com_id = rec.com_id
left outer join cw_recres as rrs on rrs.rec_id = rec.rec_id
left outer join cw_resume as res on res.res_id = rrs.res_id
left outer join cw_rectre as rcs on rcs.rec_id = rec.rec_id
left outer join cw_treatment as tre on tre.tre_id = rcs.tre_id
limit #{begin}, #{pageSize}
</select>
结果如下:
RecruitEntity{
recId=1,
recName=‘anme‘,
positionEntity=PositionEntity{...},
resumeEntities=[],
salaryEntity=SalaryEntity{...},
treatmentEntities=[TreatmentEntity{...}],
recProvince=RegionEntity{regId=2, pid=0, regName=‘文城镇‘},
recCity=RegionEntity{regId=2, pid=0, regName=‘文城镇‘},
recTown=RegionEntity{regId=2, pid=0, regName=‘文城镇‘},
}
其中三个重复数据,但是sql语句在数据库运行没有一点问题,不知哪位贤才能解答一二??
以上是关于Spring Boot+mybatis多表链接查询,重复外键的主要内容,如果未能解决你的问题,请参考以下文章