mybatis-plus中查询返回结果集的问题?

在mybatis-plus中做一个连表的查询,我返回的结果集仅仅是一个实体类,就是type中映射的MixRecordDetails。

mybatis-plus中查询。返回结果集只写resultMap标签对,没result标签对也能返回成为这个实体类?

但是我不懂,难道可以不写结果集吗?

<resultMap id="MixRecord" type="com.MixRecordDetails">
        //这里的result删除后依旧可以运行和返回结果为MixRecordDetails
        <result column="name" property="name"></result>
        <result column="id_card" property="id_card"></result>
        <result column="telphone" property="telphone"></result>
        <result column="status" property="status" ></result>
        <result column="dept" property="dept"></result>
        <result column="batch" property="batch"></result>
        <result column="num" property="num"></result>
        <result column="begin_time" property="begin_time"></result>
        <result column="end_time" property="end_time"></result>
    </resultMap>
    <select id="search" resultMap="MixRecord">
        select a.name,a.id_card,a.telphone,a.dept,a.status,a.batch,a.num,b.begin_time,b.end_time FROM mixrecord a JOIN mix_record_batch b ON a.batch = b.batch
        <where>
            <if test="mixrecord.name != null and mixrecord.name != ''">
                and a.name LIKE CONCAT('%',#{mixrecord.name},'%' )
            </if>
            <if test="mixrecord.id_card != null and mixrecord.id_card != ''">
                and a.id_card = #{mixrecord.id_card}
            </if>
            <if test="mixrecord.telphone != null and mixrecord.telphone != ''">
                and a.telphone = #{mixrecord.telphone}
            </if>
            <if test="mixrecord.dept != null and mixrecord.dept != ''">
                and a.dept LIKE CONCAT('%',#{mixrecord.dept},'%' )
            </if>
            <if test="mixrecord.batch != null and mixrecord.batch != ''">
                and a.batch LIKE CONCAT('%',#{mixrecord.batch},'%' )
            </if>
            <if test="mixrecord.status != null and mixrecord.status != ''">
                and a.batch = #{mixrecord.status}
            </if>
            <if test="mixrecord.batchId != null and mixrecord.batchId != ''">
                and b.id = #{mixrecord.batchId}
            </if>
        </where>
    </select>

 

其实这个不是 Mybatis-Plus 的,而是 Mybatis 帮你完成的,因为通过

<resultMap id="MixRecord" type="com.MixRecordDetails"> 其实就已经知道了要返回的类型,所以你可以理解为 resultMap 就是在 resultType 的基础上做了一些定制化,这个你可以通过查看 Mybatis 的源码去了解。本质上和 resultType 是一样的,定制化映射就是你写的那些 <result> 等标签。

resultMap是定义数据库字段与实体对象属性的映射

resultMap 或者 resultType  有一个就可以了, 使用resultMap 就已经映射结果集了

那是因为你的表字段与实体属性名一模一样,你换个不一样的,实体就不能接收到数据库中的值了