问题描述
使用 sharding-jdbc 时所有这些都是错误的
表架构是:
a is the pk,b and c is normal column;
在这样的映射器中:
public void insertOrUpdate(@Param("dto") XxxxDTO dto);
mybatis xml中的动态sql:
insert into xxx(a,b,c) values(#{dto.a},#{dto.b},#{dto.c}) on duplicate key update b=if(b+#{dto.add} < #{dto.limit},b+#{dto.add},b);
sql 的意思是:如果 A 已经在表中,则更新 b 列,但现在如果 b+dto.add<dto.limit
则更新它,否则什么都不做
运行时抛出这个异常:
Caused by: java.sql.sqlException: 没有为参数 4 指定值
但是,在 $
之后使用 on duplicate key update
可以使其工作。
insert into xxx(a,#{dto.c}) on duplicate key update b=if(b+${dto.add} < ${dto.limit},b+${dto.add},b);
我不知道为什么。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)