Mybatis坑之collection单属性list

今天写了一个一对多的查询用到了collection,首先是这样的

  <resultMap id="userParamMap" type="com.veoer.mind.entity.UserParam">
    <id column="u_id" jdbcType="VARCHAR" property="id" />
    <result column="company_id" jdbcType="VARCHAR" property="companyId" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="sex" jdbcType="INTEGER" property="sex" />
    <result column="mobile" jdbcType="VARCHAR" property="mobile" />
    <result column="email" jdbcType="VARCHAR" property="email" />
    <result column="id_card" jdbcType="VARCHAR" property="idCard" />
    <result column="work_code" jdbcType="VARCHAR" property="workCode" />
    <result column="position" jdbcType="VARCHAR" property="position" />
    <result column="if_delete" jdbcType="INTEGER" property="ifDelete" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="supplier_user_id" jdbcType="VARCHAR" property="supplierUserId" />
    <result column="supplier_id" jdbcType="VARCHAR" property="supplierId" />
    <collection property="supplierOrganizationIdList" column="orgrm_" javaType="java.util.ArrayList" ofType="java.lang.String"></collection>
  </resultMap>

这样的

 <select id="findByPageForSupplier" resultMap="userParamMap">
    select
    u.id as u_id, u.company_id as companyId, u.name,u.sex, u.mobile, u.email, u.id_card as id_card, u.work_code as work_code, u.position, u.if_delete as if_delete, u.update_time as update_time,
    ur.supplier_user_id as supplier_user_id,ur.supplier_id as supplier_id,orgr.supplier_organization_id as orgrm_supplier_organization_id
    from user u
    left join user_relation ur on u.id = ur.user_id
    left join user_organization_relation uor on u.id = uor.user_id
    left join organization_relation orgr on uor.organization_id = orgr.organization_id
      where  orgr.supplier_id = #{supplierId}
    and u.company_id = #{companyId} and orgr.company_id=#{companyId}  and uor.company_id = #{companyId}
      <if test="name != '' and name != null">
        and u.name like '%#{name}%'
      </if>
      <if test="time != null">
        and u.update_time > #{time}
      </if>
    </select>

查询结果是这样的

仔细看会发现,我的id和supplierOrganzationIdList里面的值一样,WTFK,我各种修改我的collection,各种查资料,感觉我的collection写的没毛病啊,但是结果始终是这样,最后机缘巧合将我的sql改了一下,把我的list查询条件调到了第一位,也就是这样

    <select id="findByPageForSupplier" resultMap="userParamMap">
    select
    orgr.supplier_organization_id as orgrm_supplier_organization_id,
    u.id as u_id, u.company_id as companyId, u.name,u.sex, u.mobile, u.email, u.id_card as id_card, u.work_code as work_code, u.position, u.if_delete as if_delete, u.update_time as update_time,
    ur.supplier_user_id as supplier_user_id,ur.supplier_id as supplier_id
    from user u
    left join user_relation ur on u.id = ur.user_id
    left join user_organization_relation uor on u.id = uor.user_id
    left join organization_relation orgr on uor.organization_id = orgr.organization_id
      where  orgr.supplier_id = #{supplierId}
    and u.company_id = #{companyId} and orgr.company_id=#{companyId}  and uor.company_id = #{companyId}
      <if test="name != '' and name != null">
        and u.name like '%#{name}%'
      </if>
      <if test="time != null">
        and u.update_time > #{time}
      </if>
    </select>

惊喜的发现查询的结果对了,坑爹啊!

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值