"nested exception is org.apache.ibatis.binding.BindingException: Parameter 'money' not found. Available parameters are [singleAccount, param1]"
当通过@Param进行注释以后
int insertSingleAccount(@Param("singleAccount") SingleAccount singleAccount);
而你的sql语句并没使用使用到注释的别名,就会出现找不到第一个属性的问题
<insert id="insertSingleAccount">
insert into single_account
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="money != null">money,</if>
<if test="categoryId != null">category_id,</if>
<if test="expensesIncome != null">expenses_income,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="remark != null ">remark,</if>
<!-- 新增user_id字段 -->
<if test="userId != null">user_id,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="money != null">#{money},</if>
<if test="categoryId != null">#{categoryId},</if>
<if test="expensesIncome != null">#{expensesIncome},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="remark != null ">#{remark},</if>
<!-- 新增user_id值 -->
<if test="userId != null">#{userId},</if>
</trim>
</insert>
原因是mybatis默认的参数为param1的param2… 而如果进行@Param注解以后,sql没有使用到,那么他不会把你的注释的参数的实体类赋值给param1,所以就找不到他的属性,
解决方法:
在没有使用到(@Param(“**”)注解的别名的时候,就不用加@Param注解