Mybatis There is no getter for property named 'userId' in 'class java.lang.Long'

本文记录并解决了在使用Mybatis进行数据库操作时遇到的参数解析问题,原因为使用特定方式引用参数导致mybatis无法正确识别,通过更改参数引用方式或使用@Param注解成功解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

记录一个Mybatis错误,搞了老半天没找到原因,
原本是这个样子的,我的parameterType参数是Long型,在下面引用时,也有注明jdbcType类型,但是一直报这个错
There is no getter for property named 'userId' in 'class java.lang.Long'
结果查询资料得出,是因为mybatis参数解析的问题。后面有机会研究一下

<!--根据用户id增加相应用户算算力值-->
    <update id="addUserHashrate" parameterType="java.lang.Long">
        update user_hashrate
        set
        current_hr = (current_hr+100) where 1=1
        <if test="userId != null">
           and user_id = #{_parameter,jdbcType=BIGINT}
        </if>
    </update>

这里直接改正为_parameter,作为参数的引用。

<!--根据用户id增加相应用户算算力值-->
    <update id="addUserHashrate" parameterType="java.lang.Long">
        update user_hashrate
        set
        current_hr = (current_hr+100) where 1=1
        <if test="_parameter != null">
           and user_id = #{_parameter,jdbcType=BIGINT}
        </if>
    </update>

还有一种解决方案就是在方法参数上,加@Param(value="userId") Long userId.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值