关于Mybatis查询中列表里的对象为null的问题解决

1. 问题修正之前

mapper.xml

<resultMap id="fileConfig" type="demo.model.dto.FileConfigModel">
    <id column="i_id" property="id"/>
    <result column="c_app_id" property="bizCode"/>
    <result column="c_desc" property="bizDesc"/>
    <result column="c_suffix" property="fileFormat"/>
    <result column="i_max_size" property="fileMaxSize"/>
    <result column="c_time" property="createTime"/>
    <result column="c_update_time" property="updateTime"/>
</resultMap>

<select id="getFileConfig" parameterType="demo.model.req.GetFileConfigReq"
        resultType="demo.model.dto.FileConfigModel">
    select c_app_id,c_desc,c_suffix,i_max_size
    from file_conf_apply where 1=1
    <if test="bizCode != null and bizCode != ''">
        and c_app_id LIKE CONCAT(CONCAT('%',#{bizCode}),'%')
    </if>
    <if test="bizDesc != null and bizDesc != ''">
        and c_desc LIKE CONCAT(CONCAT('%',#{bizDesc}),'%')
    </if>
     limit #{fromIndex},#{pageCount}
</select>

出现的问题是,select执行语句返回的list的size大于0,但是,list里面的对象为null。

 

2. 问题的解决

目前原理还没了解清楚,如果看到的朋友有知道的话,可以在博文下面留言。问题的解决办法是:

修改select语句中resultType。将resultType修改为resultMap,值为fileConfig。修改后的代码为:

<select id="getFileConfig" parameterType="demo.model.req.GetFileConfigReq"
        resultMap="fileConfig">
    select c_app_id,c_desc,c_suffix,i_max_size
    from file_conf_apply where 1=1
    <if test="bizCode != null and bizCode != ''">
        and c_app_id LIKE CONCAT(CONCAT('%',#{bizCode}),'%')
    </if>
    <if test="bizDesc != null and bizDesc != ''">
        and c_desc LIKE CONCAT(CONCAT('%',#{bizDesc}),'%')
    </if>
     limit #{fromIndex},#{pageCount}
</select>

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值