背景在执行插入语句的使用,想要使用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);,其它不变
399

被折叠的 条评论
为什么被折叠?



