踏过的坑

Scroll Down

Mybatis

1. mybatis 在使用动态sql查询的时候,在select标签中使用foreach时,不可以使用resultMap要使用resultType,否则会出现值拿不到的异常(示例使用Map)

代码

Map<String, Object> map = new HashMap<>();
  map.put("opsUserId", opsId);
  map.put("status", query.getStatus());
  map.put("statusIds", query.getAllStatus());
 amsCouponDao.findOps(map);
dao
List<OpsDetail> findOps(Map<String, Object> map)
mapper文件配置
<select id="findOps" resultType="com.troyqu.OpsDetail">
        select coupon.*,account.name as account_company from cou coupon
        left join account account on coupon.account_id = account.id
        where coupon.ops_user_id = #{opsUserId}
        <choose>
            <when test="status">
                and coupon.status = #{status}
            </when>
            <when test="status == null and statusIds != null">
                and coupon.status in
                <foreach collection="statusIds" index="index" item="item" open="(" separator="," close=")">#{item}
                </foreach>
            </when>
        </choose>
        order by coupon.created_at desc
    </select>