SpaingBoot中Mybatis外键联表查询

Mapper文件:
<?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="io.dao.gather.PeopleCollectionDao">

	<!-- 可根据自己的需求,是否要使用 -->
    <resultMap type="io.entity.gather.PeopleCollectionEntity" id="peopleCollectionMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="identity" column="identity"/>
        <result property="phone" column="phone"/>
        <result property="address" column="address"/>
        <result property="filePath" column="file_path"/>
        <result property="remark" column="remark"/>
        <result property="rank" column="rank"/>
        <result property="flag" column="flag"/>
        <result property="type" column="type"/>
        <association property="positionCollectionEntity" javaType="io.entity.gather.PositionCollectionEntity"
        column="flag" resultMap="positionCollectionMap">
        </association>
    </resultMap>

    <!-- 外键Map -->
    <resultMap type="io.entity.gather.PositionCollectionEntity" id="positionCollectionMap">
        <id property="id" column="id" />
        <result property="flag" column="flag" />
        <result property="positionX" column="position_x" />
        <result property="positionY" column="position_y" />
    </resultMap>

    <select id="queryByName" resultMap="peopleCollectionMap">
        SELECT * from tb_gather_collection_people_info people JOIN tb_gather_collection_position positon on people.flag =positon.flag where people.name=#{name}
    </select>

</mapper>



Entity文件:

package io.entity.gather;

import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;

import java.io.Serializable;

@TableName("tb_gather_collection_people_info")
public class PeopleCollectionEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 主键
     */
    @TableId
    private Long id;
    /**
     * 姓名
     */
    private String name;
    /**
     * 身份证号
     */
    private String identity;
    /**
     * 手机号码
     */
    private String phone;
    /**
     * 户籍地址
     */
    private String address;
    /**
     * 文件位置
     */
    private String filePath;

    /**
     * 备注
     */
    private String remark;
    /**
     * 序号(用于区分同行人员第几位)
     */
    private Integer rank;
    /**
     * 同一次数据采集的标识
     */
    private String flag;
    /**
     * 1,人员信息,2,同行人员,3,车主信息,4,房东信息,5,驾驶员,6,车上人员
     */
    private Integer type;

    /**
     * 采集场景外键
     */
     private PositionCollectionEntity positionCollectionEntity;
//省略getter和setter方法        
 }

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Connie1451/article/details/80319652
个人分类: SpringBoot
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭