报错:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ”meltFlowRate’ (id) values (21)’ at line 1
原因:使用mybatis动态表名的时候,表名用该用反引号括起来,我用了单引号;
以下是错误的实现:
String tableName ="meltFlowRate";
int sampleId = 21;
Map<String, Object> map = new HashMap<String, Object>();
map.put("tableName", "'" + tableName + "'");
map.put("sampleId", sampleId);
int res = common.insertSample(map);
以下是正确的实现:
String tableName ="meltFlowRate";
int sampleId = 21;
Map<String, Object> map = new HashMap<String, Object>();
map.put("tableName", "`" + tableName + "`");
map.put("sampleId", sampleId);
int res = common.insertSample(map);
本文介绍了一个关于MyBatis中动态表名使用的常见错误及修正方法。错误在于将表名用单引号括起来,而正确的做法是使用反引号。文章通过具体的示例对比展示了错误和正确代码的写法。
7927

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



