The error may exist in bshr/mapper/PfmMapper.xml ### The error may involve defaultParameterMap
问题背景:
springboot + mybatis + vue项目,IDEA开发。
绩效计划通过eid(员工编号)关联一个员工,有一个绩效计划表还有一个员工表。
关联方式为:嵌套查询。可以有两种实现方式:
第一种,不列举绩效计划表列和绩效计划bean属性的对应关系和数据类型(开始采取的方式):
<resultMap id="PRResultMap1" type="bshr.bean.EmpPlanResult"><association property="emp" javaType="bshr.bean.Employee"select="bshr.mapper.EmpMapper.getEmpByEid"column="eid"></association></resultMap>
第二种,列举出绩效计划表的列和绩效计划bean属性的对应关系以及数据类型(最终采取的方式):
<resultMap id="PRResultMap2" type="bshr.bean.EmpPlanResult"><id column="rowid" property="rowid" jdbcType="VARCHAR"/><result column="eid" property="eid" jdbcType="VARCHAR"/><result column="submitdate" property="submitdate" jdbcType="TIMESTAMP"/><result column="startdate" property="startdate" jdbcType="TIMESTAMP"/><result column="enddate" property="enddate" jdbcType="TIMESTAMP"/><result column="g_taskpoint" property="g_taskpoint" jdbcType="INTEGER"/><result column="g_appoint" property="g_appoint" jdbcType="INTEGER"/><result column="g_timepoint" property="g_timepoint" jdbcType="INTEGER"/><result column="r_taskpoint" property="r_taskpoint" jdbcType="INTEGER"/><result column="r_appoint" property="r_appoint" jdbcType="INTEGER"/><result column="state" property="state" jdbcType="INTEGER"/><result column="remark" property="remark" jdbcType="VARCHAR"/><result column="deleted" property="deleted" jdbcType="TINYINT"/><association property="emp" javaType="bshr.bean.Employee"select="bshr.mapper.EmpMapper.getEmpByEid"column="eid"></association></resultMap>
当然,也可以通过嵌套resultmap的方式关联两个表,但是定义resultmap和进行查询时,相对来说都会比较繁琐,所以一开始我就没有采取这种方式。
在查询绩效计划时,想要根据员工名称进行筛选。
问题描述:
后端程序能够正常启动,但是前端进行相关查询操作时,从后端传过来的数据有问题。chrome浏览器,F12可见:
1.绩效计划对象中的eid为null,但是有根据该eid查到的emp。
2.后端传来的count(前端分页,后端传过来的数据的个数)为null,甚至根本就不显示。
后端因为有相应的try...catch...语句所以打印了调用栈,显示错误:
org.springframework.jdbc.BadSqlGrammarException:
### Error querying 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 'from emp_pfmplanresult ep ,employee empwhere ep.eid = emp.id' at line 2
### The error may exist in bshr/mapper/PfmMapper.xml
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select count * from emp_pfmplanresult ep ,employee emp where ep.eid = emp.id and ep.state = 0
### 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 'from emp_pfmplanresult ep ,employee empwhere ep.eid = emp.id' 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 'from emp_pfmplanresult ep ,employee empwhere ep.eid = emp.id' at line 2at ...
(在本问题中,前端一个请求(获取满足条件的绩效计划),后端进行两次查询:
1.查询满足条件的绩效计划信息(同时要满足前端分页的约束,即页数以及每页显示的数据条数);
2.查询满足条件的绩效计划的数量(不必考虑页数和每页的数据条数)
两次查询报错相似。)
问题分析:
根据错误信息:
### The error may involve defaultParameterMap
### The error occurred while setting parameters
可知,与参数有关。
复制这两行信息,到浏览器,也有人遇到过类似的问题,有人说是因为参数类型不明确所致。
解决方案:
将问题背景中描述的关联:嵌套查询的实现改为第二种方式,问题解决。
(提示,问题虽然解决了,但未必是因为参数类型不明确,因为原本采取的嵌套查询的方式不仅没有指明参数类型,也没有指明参数,就是没有指明列和属性以及其对应关系。可以通过实验,删除上述代码中的参数类型相关的语句,看运行结果。当然也可以通过深入了解mybatis的运行机制和语法在理论上得到答案。)
启发:
熟悉mybatis的工作流程或许能更早的发现导致的问题的可能原因(参数不明)。
最终解决此问题的关键是:发现了那两行错误信息,同时在网上找到了相似问题,并发现了可能的问题原因,且尝试了第二种嵌套查询的方式。
由此可见,错误信息是首要参考,网友们的问题和回答也是非常重要的参考,必要的知识有助于我们在找到可能的原因后快速想到如何修改。
最后,大胆猜想,小心尝试。
The error may exist in bshr/mapper/PfmMapper.xml ### The error may involve defaultParameterMap相关推荐
- Error building SqlSession. ### The error may exist in com/itrs/mapper/OrderMapper.xml ### The error
报错信息 org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession. ### The error ...
- mybatis错误:bad SQL grammar [];error occurred while setting parameters;involve defaultParameterMap处理
业务描述:由于处理数据量庞大,多表进行拆分,每次任务新建一个表.在往新建表(表名要传参)插入数据时,提示错误: Error updating database. Cause: java.sql.SQ ...
- Mybatis莫名报错或Mapper.xml配置后爆红或显示The error may exist in com/jdsydwr/dao/UserMapper.java找不到Mapper接口的修改方法
报错内容 org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession. ### The erro ...
- ### Error building SqlSession. ### The error may exist in com/itrs/mapper/UserMapper.xml ### Cause:
项目场景: Mybatis 问题描述: org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession ...
- Error building SqlSession.The error may exist in cn/library/mapper/UserMapper.xml(Mybatis搭建测试中的错误解决)
一.问题详情 IDEA2019中在搭建Mybatis简化DAO操作时报错: 错误分析:初步判断存在于配置文件UserMapper.xml中. 错误详情: org.apache.ibatis.excep ...
- Mybatis关于The error may exist in *mapper.xml的一种报错,读取不到实体类,别名问题
最近在学习mybatis,错误: 编译器找不到*mapper.xml,更准确的说是找不到实体类,挺低级的错误.报错信息如下: D:\Java\jdk1.8.0_171\bin\java.exe jav ...
- ### Error building SqlSession.### The error may exist in entity/UserMapper.xml
错误样式: 核心错误提示: ### Error building SqlSession. ### The error may exist in entity/UserMapper.xml 原因:就是M ...
- Error parsing Mapper XML. The XML location is ‘com/xxxxx/com/system/mapper/XXXXMapper.xml‘.
Error parsing Mapper XML. The XML location is 'com/xxxxx/com/system/mapper/XXXXMapper.xml'. 检查 xxxxM ...
- SSM中mybtis报错### The error may involve defaultParameterMap ### The error occurred while setting param
首先是前端弹出错误框如下: 查看后台报错信息如下 ### Cause: java.sql.SQLException: Error ; uncategorized SQLException; SQL s ...
最新文章
- Kaggle大牛小姐姐自述:我是怎么成为竞赛中Top 0.3%的 | 干货攻略
- 用Windows Live Writer在51CTO写博客
- JavaWeb(三)——Maven的安装、配置及在IDEA中的使用
- boost::type_index模块constexpr相关的测试程序
- 16、java中的集合(3)
- 【转】2.3async中必须始终返回Task(@Ron.liang)
- 博客系统如何随机插入大量文章数据
- android_Media
- python学习第二十三节(反射以及小工具)
- matlab 马丢函数,振幅调制产生马丢光束的方法与流程
- 【优化算法】多目标哈里斯鹰优化算法(MOHHO)【含Matlab源码 1596期】
- linux应用程序逆向,Linux下查看并下载命令源码包(依据命令/应用程序逆向获取并且安装其所属源码包)...
- 路由模式 -- ADSL账号密码拨号
- 微信消息模板配置文档对接himall
- 遗传算法求解TSP问题及MTATLAB代码
- 详解高速缓存存储器的3种映射方式
- 【java】java如何保留时分秒存取mySql中的datetime类型数据的方法 及 显示时间与数据库存放时间相差n小时的解决方法
- Android 字体颜色渐变效果 Span实现
- $NOIP 2018 PJ游记[ZJ]$
- 华纳云:MySQL数据丢失的原因是什么及怎么解决