使用Mybatis 对数据库进行多对一嵌套查询,报错?

问题

使用Mybatis 对数据库进行多对一嵌套查询,报错信息大致如下:

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.sql.SQLSyntaxErrorException: Unknown column 'id' in 'where clause'
### The error may exist in Student.xml
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select * from tea_table where id=?
### Cause: java.sql.SQLSyntaxErrorException: Unknown column 'id' in 'where clause'
    at StudentDao.getAll(StudentDao.java:9)
    at Text.main(Text.java:9)
Caused by: java.sql.SQLSyntaxErrorException: Unknown column 'id' in 'where clause'

数据库结构及参数设置

数据库结构image.pngimage.pngimage.pngimage.png外键已经正确设置.png
其中tid是外键【关联tea_table】
stu_id,tea_id均为各自数据表主键,通过结果嵌套查询正常出结果
代码全部参考于https://edu.aliyun.com/lesson...视频【问题代码约在视频第22:40~30:15处】,题主已经按照视频中的代码进行了排错,但是不幸错误依然存在

运行环境

interllij开发版2021.3
jdk1.8
mysql及其gui
mybatis框架
该项目为基于maven的Javaweb项目

个人对报错信息初步分析

通过对idea报错信息的分析,目前可以确定应该与参数#{id}未能正常传入有关,但是,具体因为什么导致的及如何解决该问题并无头绪,通过百度亦未搜索到相关经验

项目排错下载

因为项目代码较多,且题主不知道是什么原因导致idea出现报错,故将项目完整放在和彩云以方便排错【链接: https://caiyun.139.com/m/i?0d... 提取码:BRb5 】

阅读 3.1k
1 个回答
Unknown column 'id' in 'where clause'

你的表是 stu_id 不是 id

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题