解决mybatis中#{}导致的The error may involve defaultParameterMap的问题
今天想实现给指定表插入数据,出现了
### Error updating database. Cause: java.sql.SQLSyntaxErrorException: 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 ''api_assets0' (id,name, level,type,file_id)
values
(3' at line 1
### The error may exist in file [E:\java\project\admin\devide\target\classes\mapper\ApiAssetsMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: insert into ? (id,name, level,type,file_id) values (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?) , (?,?, ?,?,?)
### Cause: java.sql.SQLSyntaxErrorException: 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 ''api_assets0' (id,name, level,type,file_id)
values
(3' at line 1
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: 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 ''api_assets0' (id,name, level,type,file_id)
values
mapper里
int insert(@Param("list") List<ApiAssets> list,@Param("one") String one);
XML里
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.abc.devide.demo.mapper.ApiAssetsMapper">
……
<insert id="insert">
insert into #{one} (id,name, level,type,file_id)
values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.id},#{item.name}, #{item.level},#{item.type},#{item.fileId})
</foreach>
</insert> </mapper>
解决方法:
使用 ${} 接受表名,#{}接受其他参数
将insert部分改为
<insert id="insert">
insert into ${one} (id,name, level,type,file_id)
values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.id},#{item.name}, #{item.level},#{item.type},#{item.fileId})
</foreach>
</insert>
就可以成功执行了
${} 同 #{} 的区别 查看
解决mybatis中#{}导致的The error may involve defaultParameterMap的问题的更多相关文章
- 解决mybatis中转义字符的问题
xml格式中不允许出现类似“>”这样的字符,有如下两种解决方法 方法一:使用转义字符 SELECT * FROM test WHERE 1 = 1 AND start_date <= CU ...
- 解决mybatis中 数据库column 和 类的属性名property 不一致的两种方式
解决方式way1:resultMap (1)studentMapper.xml <!-- 当数据库的字段名 和 类的属性名 不一致的时候的解决方式:2种 way1--> <selec ...
- [已解决] MyBatis 中bind用法
JAVA: TC_ENTR_FLOW selectFlowForUpdate(String ENTR_ID); XML: <select id="selectFlowForUpdate ...
- ### The error may involve defaultParameterMap ### The error occurred while setting parameters
Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Query was empty; bad SQL grammar [ ...
- “mybatis 中使用foreach 传
为了帮助网友解决“mybatis 中使用foreach 传”相关的问题,中国学网通过互联网对“mybatis 中使用foreach 传”相关的解决方案进行了整理,用户详细问题包括:mybatismap ...
- 学习Spring Boot:(十二)Mybatis 中自定义枚举转换器
前言 在 Spring Boot 中使用 Mybatis 中遇到了字段为枚举类型,数据库存储的是枚举的值,发现它不能自动装载. 解决 内置枚举转换器 MyBatis内置了两个枚举转换器分别是:org. ...
- 在mybatis中使用存储过程报错java.sql.SQLException: ORA-06550: 第 1 行, 第 7 列: PLS-00905: 对象 USER1.HELLO_TEST 无效 ORA-06550: 第 1 行, 第 7 列:
hello_test是我的存储过程的名字,在mapper.xml文件中是这么写的 <select id="getPageByProcedure" statementType= ...
- 解决MWPhotoBrowser中的SDWebImage加载大图导致的内存警告问题
下面两种现象,用同一种方法解决 1.解决MWPhotoBrowser中的SDWebImage加载大图导致的内存警告问题 2.突然有一天首页访问图片很慢,至少隔20多秒所有图片才会出来.(解析:app使 ...
- Android中解决图像解码导致的OOM问题
Android中解决图像解码导致的OOM问题 原文链接:http://blog.csdn.net/zjl5211314/article/details/7042017
随机推荐
- NIO ByteBuffer的allocate与allocateDirect区别(HeapByteBuffer与DirectByteBuffer的区别)
在Java中当我们要对数据进行更底层的操作时,一般是操作数据的字节(byte)形式,这时经常会用到ByteBuffer这样一个类. ByteBuffer提供了两种静态实例方式: public stat ...
- 针对接口编程能帮助达到面向对象开发和设计中"低耦合"的要求. 某公司...打印机...(笔试中遇到的题目)
针对接口编程能帮助达到面向对象开发和设计中"低耦合"的要求. 举个例子:某公司有一台特殊打印机,还可以使用一年,一年后可能换为另一种打印机,这两种打印机都特殊而贵. ...
- 快捷键-Visual Studio Code快捷键
Shift+Enter 在Python终端中运行选定内容/行 C
- Exceptionless - 本地搭建
搭建环境:Windows 10 参与文档:https://github.com/exceptionless/Exceptionless/wiki/Self-Hosting 运行环境: .NET 4.6 ...
- 一文读懂Java线程状态转换
前言 本文描述Java线程线程状态及状态转换,不会涉及过多理论,主要以代码示例说明线程状态如何转换. 基础知识 1. 线程状态 Thread源码中的状态说明: 线程可以有6种状态: New(新建) R ...
- 洛谷 p1387最大正方形
洛谷 p1387最大正方形 题目描述 在一个n*m的只包含0和1的矩阵里找出一个不包含0的最大正方形,输出边长. 输入格式 输入文件第一行为两个整数n,m(1<=n,m<=100),接下来 ...
- .NetCore之基础
.NetCore几大特点 这篇文章主要从.NetCore全面开源.依赖注入.包引入.跨平台.应用服务器的特点来入手.大约需要10分钟的阅读时间. 与.Net的区别 在.Net与.NetCore在代码编 ...
- 隐马尔科夫模型(Hidden Markov Models) 系列之四
转自:http://blog.csdn.net/eaglex/article/details/6430389 前向算法(Forward Algorithm) 一.如果计算一个可观察序列的概率? 1 ...
- Direct Access to Video Encoding and Decoding
来源:http://asciiwwdc.com/2014/sessions/513 Direct Access to Video Encoding and Decoding Session 5 ...
- IDEA安装(2019.2版)
IDEA安装(2019.2版) 前段时间在公司实习接触过现下很火的 IDE,这里我根据搜集到的资料以及自己的实际操作整合了这篇博客,包括了安装和破解 IDEA,借此打开学习之旅. IntelliJ ...