解决org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ‘cwRecalcu

问题描述

org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'cwRecalculate' in 'class org.springblade.modules.cwxt.cwrecalculate.vo.CwRecalculateVO'

mapper文件的代码:

List<CwOperateRecordVO> selectCwOperateRecord(CwOperateRecordVO cwOperateRecord);
mapper.xml文件的代码:

 

  <select id="selectCwOperateRecord" resultMap="cwOperateRecordResultMap">
        select * from xmkf_cw_operate_record a
        where a.is_deleted = 0
        <include refid="selectCwOperateRecordWhere"/>
    </select>

    <sql id="selectCwOperateRecordWhere">
        <if test="cwOperateRecord.startTime != null">
            and a.create_time >= #{cwOperateRecord.startTime}
        </if>
        <if test="cwOperateRecord.endTime != null">
            and a.create_time  &lt;= #{cwOperateRecord.endTime}
        </if>
        <if test="cwOperateRecord.operator != null and cwOperateRecord.operator != ''">
            <bind name="name" value="'%'+ cwOperateRecord.operator +'%'"/>
            and a.operator like #{name}
        </if>
        <if test="cwOperateRecord.operateFunction != null">
            and a.operate_function = #{cwOperateRecord.operateFunction}
        </if>
        <if test="cwOperateRecord.type != null">
            and a.type = #{cwOperateRecord.type}
        </if>
    </sql>

解决方案:

方案1:

mapper.xml文件不识别#{objectName.propertyName}语法,将objectName.去掉
  <select id="selectCwOperateRecord" resultMap="cwOperateRecordResultMap">
        select * from xmkf_cw_operate_record a
        where a.is_deleted = 0
        <include refid="selectCwOperateRecordWhere"/>
    </select>

    <sql id="selectCwOperateRecordWhere">
        <if test="startTime != null">
            and a.create_time >= #{startTime}
        </if>
        <if test="endTime != null">
            and a.create_time  &lt;= #{endTime}
        </if>
        <if test="operator != null and operator != ''">
            <bind name="name" value="'%'+ operator +'%'"/>
            and a.operator like #{name}
        </if>
        <if test="operateFunction != null">
            and a.operate_function = #{operateFunction}
        </if>
        <if test="type != null">
            and a.type = #{type}
        </if>
    </sql>

在Mapper.xml文件中,使用对象来传递数据,可以将数据从Java代码传输到数据库,也可以将数据从数据库传输到Java代码。通常情况下,我们将对象中的属性名与数据库表的列名进行对应,以便在Mapper文件中使用这些属性来构建SQL语句。

在使用对象的属性名填充Mapper.xml文件数据时,不需要在属性名前面添加对象名称。这是因为对象是一个Java类,而不是一个数据库表,它的属性名称是在Java类中定义的,而不是在数据库表中定义的。

在Mapper文件中,我们使用#{propertyName}来引用DTO的属性。如果我们在属性名前面添加了对象名称,例如#{objectName.propertyName},则会导致语法错误,因为Mapper.xml文件不能识别这个语法。

注:个人认为,如果条件查询的条件太多,这么改太浪费时间,可以采取方案2

方案2:

直接在mapper文件的方法中,参数列表加上@Param

List<CwOperateRecordVO> selectCwOperateRecord(@Param("cwOperateRecord") CwOperateRecordVO cwOperateRecord);

在mapper接口上面添加@Param用来给传入参数命名,那么参数就被转化为Mybatis内置对象。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值