mysql #{}和$ {}使用出错,导致参数从varchar变int 运行错误

区别:#{}是预编译处理,$ {}是字符串替换

我的删除delete的SQL语句因为表名是动态的,所以使用的$ {}来设置表名,后面的where条件顺手(复制粘贴)也写成了${},导致传递参数的值本来是字符串类型却编译成了数字,导致执行后出现数据错误。

mybatis SQL语句如下:

 delete  from ${tableName}
 		where test_id = ${resultDetail.test_id}
          and push_id = ${resultDetail.push_id}
          and user_id = ${resultDetail.user_id}
          and result_id = ${resultDetail.result_id} ;

执行的SQL:

 
 delete
 FROM x_resultanswer_53
 WHERE test_id = 53 
 and push_id = 47024 
 and user_id = 2623488688666648650 
 and result_id = 2623488688666650227; 
 

问题:
在这里插入图片描述

我需要的SQL:

 delete
 FROM x_resultanswer_53
 WHERE test_id = 53 
 and push_id = 47024 
 and user_id = '2623488688666648650' 
 and result_id = '2623488688666650227' ; 
 

知识点是明白的,问题也不算大,但是项目跑起来的时候导致一直数据不对……
记录一下,细心!细心!细心!

猜你喜欢

转载自blog.csdn.net/weixin_44934104/article/details/126502884