MyBatis中的resultMap两个association

查询一个类,需要带出来其他两个类

投递简历Vo
@ApiModel(value="投递简历Vo")
public class SendResumeVo implements Serializable {
	// 省略其他属性
	
	@ApiModelProperty(value="招聘信息ID" )
	private	Long recruitId;

	@ApiModelProperty(value="招聘信息Vo" )
	private	RecruitVo recruitVo;

	//求职者ID
	@ApiModelProperty(value="求职者ID" )
	private	Long userId;
	
	@ApiModelProperty(value="简历ID" )
	private	Long resumeId;

	@ApiModelProperty(value="简历Vo" )
	private	ResumeVo resumeVo;
}
投递简历xml
<?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">
<mapper namespace="com.xxx.mapper.SendResumeMapper">
	<!--投递简历Vo-->
	<resultMap id="resultMap" type="com.xxx.entity.SendResumeVo">
		<id column="id" property="id"/>
		<result column="company_id" property="companyId"/>
		<result column="recruit_id" property="recruitId"/>
		<result column="user_id" property="userId"/>
		<result column="resume_id" property="resumeId"/>
		<result column="status" property="status"/>
		<result column="create_date" property="createDate"/>
		<!--association column的id是对应查询片段中的变量,recruit_id是当前resultMap中查询的列名-->
		<association property="recruitVo" select="com.xxx.mapper.RecruitMapper.selectOneVo" column="{id=recruit_id}" />
		<association property="resumeVo" select="com.xxx.mapper.ResumeMapper.selectOneVo" column="{id=resume_id}" />
	</resultMap>
	
	<select id="selectPageSendResumeVo" resultMap="resultMap">
        SELECT
        	省略...,
        	resume_id,
        	recruit_id
        FROM
        	send_resume AS sr
        <where>
			sr.user_id = #{userId} 
        </where>
    </select>
</mapper>
	```
#### 其他两个xml的片段
```xml
	<!--据说被引用的sql片段这里一定要写 parameterType="java.util.Map",实测不写也ok-->
	<select id="selectOneVo" parameterType="java.util.Map" resultType="com.xxx.entity.RecruitVo">
		SELECT
		省略...
		FROM
		recruit AS r
		<where>
			<if test="id!=null">
				AND r.id=#{id}
			</if>
		</where>
		LIMIT 1
	</select>
```

```xml
	<!--据说被引用的sql片段这里一定要写 parameterType="java.util.Map",实测不写也ok-->
	<select id="selectOneVo" parameterType="java.util.Map" resultType="com.xxx.entity.ResumeVo">
		SELECT
		省略...
		FROM
		resume AS r
		<where>
			<if test="id!=null">
				AND r.id=#{id}
			</if>
		</where>
		ORDER BY r.update_date DESC
		LIMIT 1
	</select>
```

#### 查询结果json
```json
{
        "id": 1,
        "companyId": 1,
        "recruitId": 1,
        "recruitVo": {
          "id": 1,
          "companyId": 1,
          "companyName": "能力有限",
          "companyType": "1",
          "industryId": 0,
          "industryLabel": "",
          "jobStationId": 2,
          "jobStationLabel": "印前",
          "jobPosition": null,
          "jobAreaId": 0,
          "jobAreaLabel": "",
          "hiringNumber": 0,
          "gender": "1",
          "genderLabel": "男",
          "educationLevel": "1",
          "educationLevelLabel": "小学",
          "workingYears": "1",
          "workingYearsLabel": "一年及以下",
          "salaryLevel": "3",
          "salaryLevelLabel": "3000-4000元",
          "endDate": "2020-02-02 00:00:00",
          "jobRequirements": null,
          "jobDuties": null,
          "createDate": "2020-02-23 18:25:08",
          "updateDate": "2020-02-23 18:40:33",
          "viewCount": 2
        },
        "userId": 1,
        "resumeId": 1,
        "resumeVo": {
          "id": 1,
          "userId": 0,
          "name": "lzx",
          "gender": "1",
          "genderLabel": "男",
          "birthDate": "2020-02-20 00:00:00",
          "nativePlaceProvinceId": 0,
          "nativePlaceProvinceLabel": "",
          "phone": "17051018721",
          "photo": null,
          "img": null,
          "educationLevel": "1",
          "educationLevelLabel": "小学",
          "workingYears": "1",
          "workingYearsLabel": "一年及以下",
          "livingCityId": 0,
          "livingCityLabel": "",
          "workingStatus": "1",
          "workingStatusLabel": "在职,看看新计划",
          "industryId": 0,
          "industryLabel": "",
          "jobStationId": 0,
          "jobStationLabel": "",
          "jobPosition": "wz",
          "salaryLevel": "1",
          "salaryLevelLabel": "2000元及以下",
          "avatar": "http://aa.jpg",
          "workExperience": "1",
          "experienceDesc": null,
          "specialSkill": "",
          "selfEvaluation": null,
          "introduce": "hfsjfsf",
          "jobExpect": "ex",
          "advantage": "1,2,3",
          "advantageLabel": "形象好,气质佳,能出差",
          "viewCount": 0,
          "inviteCount": 0,
          "createDate": "2020-02-23 16:53:07"
        },
        "status": "1",
        "createDate": "2020-02-25 12:14:24"
      }
      ```
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值