"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注解

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐