困扰了三天的问题,报错内容如下

2020-08-10 17:31:57.501  INFO 3040 --- [nio-8880-exec-2] c.h.r.a.controller.QuestionController    : insertQuestion: params data ===> [{"answer":"你是猪吗","degree":0,"domain":0,"image":"你是猪吗","question":"你是猪吗"}]
2020-08-10 17:31:57.609  INFO 3040 --- [nio-8880-exec-2] o.s.b.f.xml.XmlBeanDefinitionReader      : Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
2020-08-10 17:31:57.673 ERROR 3040 --- [nio-8880-exec-2] com.hi.rongyao.base.BaseController       :   请求路径:/question/insert  请求方式:POST  url拼接参数:null
2020-08-10 17:31:57.677  WARN 3040 --- [nio-8880-exec-2] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.jdbc.BadSqlGrammarException:
### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'option, image, answer, degree, domain)values' at line 2
### The error may involve com.hi.rongyao.affair.mapper.QuestionMapper.insertQuestion-Inline
### The error occurred while setting parameters
### SQL: insert into  question (          question, option, image, answer, degree, domain         )         values                     (           ?, ?, ?, ?, ?, ?          )
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'option, image, answer, degree, domain)values' at line 2
; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'option, image, answer, degree, domain)values' at line 2]

1、mybatis

 <!-- 新增问题  --><insert id="insertQuestion" parameterType="java.util.List"><!-- selectKey获取新增的主键 --><selectKey resultType="int" order="AFTER" keyProperty="id">select last_insert_id() as id</selectKey>insert into <include refid="table_name"></include>(question, option, image, answer, degree, domain)values<foreach collection="list" item="item" index="index" separator=",">(#{item.question}, #{item.option}, #{item.image}, #{item.answer}, #{item.degree}, #{item.domain})</foreach></insert> 

2、实体

public class Question {@Getter @Setter private Integer id;@Getter @Setter private String question;   // 问题@Getter @Setter private String option;   // 选项列表@Getter @Setter private String answer; // 答案@Getter @Setter private Integer degree;  // 难度 0-低 1-中 2-高@Getter @Setter private Integer domain;  // 范畴@Getter @Setter private String image;    // 图片@Getter @Setter private Date createTime; // 创建时间@Getter @Setter private Date updateTime;   // 更新时间
}

3、mapper

// 批量插入int insertQuestion(List<Question> list);

4、controller

    // 批量插入@RequestMapping(value = "/insert", method = RequestMethod.POST)public @ResponseBody ReturnObject insert(@RequestBody List<Question> list) {logger.info("insertQuestion: params data ===> " + JSON.toJSONString(list));questionService.insertQuestion(list);return new ReturnObject(ReturnCode.SUCCESS);}

由于是小白,一开始怎么也找不到问题原因所在,今天终于弄明白,原来是使用了mysql的关键字 option 导致的

天杀的,足足困扰了我三天,百思不得其解,小白踩的坑要填一下了

传送门,msql 保留关键字

https://www.cnblogs.com/wuyifu/p/5949764.html

java mybatis (批量) 插入实体报多个问号相关推荐

  1. mybatis批量插入oracle报表达式,mybatis oracle两种方式批量插入数据

    mybatis在oracle中批量插入数据时,单次批量大小有限制,批量插入时,单次批量过大,也会影响插入性能.故程序端也需要对应的限制. BEGIN insert into blacklist (id ...

  2. oracle批量插入报错,[数据库]Mybatis 批量插入数据 关于Oracle 批量插入报错:ORA

    [数据库]Mybatis 批量插入数据 关于Oracle 批量插入报错:ORA 0 2020-08-19 08:00:06 Mybatis 批量插入数据 关于Oracle 批量插入报错:ORA-009 ...

  3. Mybatis 批量插入报ORA-00933: SQL 命令未正确结束

    Mybatis 批量插入报ORA-00933: SQL 命令未正确结束 错误出现的场景是这样的,将多个月份的1000条数据分别插入到各月份表中. MySQL中,批量插入数据到表,会在一定程度提高效率. ...

  4. 解决Oracle+Mybatis批量插入报错:SQL 命令未正确结束

    Mybatis批量插入需要foreach元素.foreach元素有以下主要属性: (1)item:集合中每一个元素进行迭代时的别名. (2)index:指定一个名字,用于表示在迭代过程中,每次迭代到的 ...

  5. MyBatis 批量插入数据的 3 种方法

    批量插入功能是我们日常工作中比较常见的业务功能之一,之前我也写过一篇关于<MyBatis Plus 批量数据插入功能,yyds!>的文章,但评论区的反馈不是很好,主要有两个问题:第一,对 ...

  6. 公司新来个同事,MyBatis批量插入10w条数据仅用2秒,拍案叫绝!

    批量插入功能是我们日常工作中比较常见的业务功能之一,今天咱们来一个 MyBatis 批量插入的汇总篇,同时对 3 种实现方法做一个性能测试,以及相应的原理分析. 先来简单说一下 3 种批量插入功能分别 ...

  7. 批量插入数据库语句java_java相关:MyBatis批量插入数据到Oracle数据库中的两种方式(实例代码)...

    java相关:MyBatis批量插入数据到Oracle数据库中的两种方式(实例代码) 发布于 2020-7-22| 复制链接 本文通过实例代码给大家分享了MyBatis批量插入数据到Oracle数据库 ...

  8. mybatis批量插入(insert)和批量更新(update)

    文章目录 一.Mybatis批量插入 二.批量更新 前言:这两天在做mybatis批量插入和更新的时候,对这块不是很清楚,所以今天写篇文章,巩固加深印象. 一.Mybatis批量插入 批量插入的sql ...

  9. 【SpringBoot项目中使用Mybatis批量插入百万条数据】

    SpringBoot项目中使用Mybatis批量插入百万条数据 话不多说,直接上代码,测试原生批处理的效率 开始测试 背景:因为一些业务问题,需要做多数据源,多库批量查询.插入操作,所以就研究了一下. ...

  10. MyBatis批量插入(sqlserver BULK INSERT)

    MyBatis批量插入: 1. foreach方式 2.sqlsession + sqlsession.flushStatements方式: //        SqlSession sqlSessi ...

最新文章

  1. 全方位,多角度理解ThreadLocal
  2. 科研文献|了解多个含水层中微生物砷的迁移:DNA 和 RNA 分析的见解
  3. Mysql 拿指定经纬度与数据库多条经纬度进行距离计算
  4. coolite TreePanel CheckBox联动
  5. python学习笔记(四)字典(dict)
  6. (转)2-sat 专题
  7. excel中怎么把超链接的结果(图片)直接显示出来_把500张产品图片导入Excel里?用这个方法可超速完成,码住...
  8. python中 将字符串和字典的相互转换
  9. django python3 异步_详解配置Django的Celery异步之路踩坑
  10. win7 vs2010 安装cocos2d-x
  11. 2.中小型企业通用自动化运维架构 -- Ansible 安装
  12. 计算机专业英语1700+
  13. Docker 运行stress
  14. 常见的服务器虚拟化产品都有哪些,桌面虚拟化产品主要有哪几种主流技术分类呢?...
  15. 从π与e开始 理解正态分布
  16. 她全奖赴海外读博,一作发Science,毅然回国后任东南大学教授!
  17. 训练好的vgg报错RuntimeError:mat1 and mat2 shapes cannot be multiplied(512*49 and 25088*4096)
  18. ERP环境下内部控制系统建立与实施要点
  19. 基于keil5 的stm32F103C8T6的ST-LINK V2的仿真器使用
  20. hdu 1686 Oulipo(kmp)

热门文章

  1. Photoshop CC2018软件
  2. C++基础知识(7)
  3. 怎么获取自定义核算项目里某一个类型的数据:做f7
  4. 求两个列表的交集、并集和补集
  5. 排序算法伪代码以及python实现——插入,归并,快速,堆,计数
  6. ”此网站尚未经过身份验证“问题的解决办法
  7. fatal: unable to access ‘https://github.com/thm123/algos.git/‘: Received HTTP code 400 from proxy af
  8. GPU设备架构全面解析(持续更新ing)
  9. 基于 Verilog 的经典数字电路设计(14)移位寄存器
  10. php kb转换成字节,将kB换算为MB (千字节换算为兆字节)