kiyokiwa 2021-03-04 13:50 采纳率: 81.8%
浏览 892
已结题

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>
  • 写回答

4条回答 默认 最新

  • 三岁丫 2021-03-06 16:05
    关注

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

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 7月23日
  • 已采纳回答 7月15日

悬赏问题

  • ¥15 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败