记录一个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
.