mybatis的 @param不能和实体类一起使用

背景在执行插入语句的使用,想要使用selectkey 获取到插入之后的标识码,但是这个语句同时服务于 现状表(A)和历史表(A_ls),所以就需要一个字段控制插入那个表,最初使用的 isHIs 来控制是插入 A 还是A_ls

因此DAO 那里就的方法就写成了 Long saveA(A a ,@Param(“isHis”) @Param(“isHis”) boolean isHis) ;

对应的插入语句为

 <insert id="saveA" parameterType="org.example.A">
        <selectKey keyProperty="id" order="BEFORE" resultType="Long">
            <if test="_databaseId=='postgresql'">
                 // 获取 A 表的 id
            </if>
            <if test="_databaseId=='mysql'">
                <choose>
                    <when test="isHis">
                      // 获取A_ls表的Id
                    </when>
                    <otherwise>
                        // 获取A 的Id
                    </otherwise>
                </choose>
            </if>
        </selectKey>
        insert into
        <choose>
            <when test="isHis">
               A_ls
            </when>
            <otherwise>
                A
            </otherwise>
        </choose>
        (//A表要插入的字段)
        values(// A表要插入的字段的值)
    </insert>

报错信息
在这里插入图片描述

改进方法 把参数 isHis 去掉,加到插入的实体类中方法变为Long saveA(A a);,其它不变

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值