我的BUG合集

MyBatis -- BUG集

bug 1、

提示、

org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in mybatis/mappers/empMapper.xml
### The error occurred while processing mapper_resultMap[deptRM]
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'mybatis/mappers/empMapper.xml'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'deptRM'.  Cause: java.lang.ClassNotFoundException: Cannot find class: deptRM

原因、

        在 xml 映射文件的 select 标签中 ,错误使用了 resultType="deptRM"

<select id="selectDeptById" resultType="deptRM">
    select dept_id,dept_name from dept
</select>

解决办法、

        把 resultType="deptRM" 改为 resultMap="deptRM"

<select id="selectDeptById" resultMap="deptRM">
    select dept_id,dept_name from dept
</select>

bug2、

提示、

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.apache.ibatis.executor.ExecutorException: Statement returned more than one row, where no more than one was expected.
### The error may exist in mybatis/mappers/empMapper.xml
### The error may involve com.jt.springboot_demo3_mybatis.mapper.EmpMapper.selectDeptById
### The error occurred while handling results
### SQL: select dept_id,dept_name from dept
### Cause: org.apache.ibatis.executor.ExecutorException: Statement returned more than one row, where no more than one was expected.

原因、

        在 xml 映射文件的 sql 语句编写中 ,条件查询没有 where 条件

<select id="selectDeptById" resultMap="deptRM">
    select dept_id,dept_name from dept
</select>

解决方法、

        添加 where 子句

<select id="selectDeptById" resultMap="deptRM">
    select dept_id,dept_name from dept where dept_id = #{dept_id}
</select>

bug3、

提示、

org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in mybatis/mappers/deptMapper.xml
### The error occurred while processing mapper_resultMap[deptRM]
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'mybatis/mappers/deptMapper.xml'. Cause: org.apache.ibatis.builder.BuilderException: Ambiguous collection type for property 'lists'. You must specify 'javaType' or 'resultMap'.

原因、

        尝试使用左连接直接查询,使用失败,理解不够

解决方法、

        使用子查询

bug4、

提示、

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.apache.ibatis.reflection.ReflectionException: Could not set property 'lists' of 'class com.jt.springboot_demo3_mybatis.pojo.Dept' with value '[Emp(empId=1, empName=妲己, empAge=18, dept=null), Emp(empId=5, empName=小乔, empAge=18, dept=null), Emp(empId=6, empName=大乔, empAge=19, dept=null)]' Cause: org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'lists' in 'class com.jt.springboot_demo3_mybatis.pojo.Dept'
### The error may exist in mybatis/mappers/deptMapper.xml
### The error may involve com.jt.springboot_demo3_mybatis.mapper.DeptMapper.findEmp
### The error occurred while handling results
### SQL: select emp_id,emp_name,emp_age from emp where dept_id = ?
### Cause: org.apache.ibatis.reflection.ReflectionException: Could not set property 'lists' of 'class com.jt.springboot_demo3_mybatis.pojo.Dept' with value '[Emp(empId=1, empName=妲己, empAge=18, dept=null), Emp(empId=5, empName=小乔, empAge=18, dept=null), Emp(empId=6, empName=大乔, empAge=19, dept=null)]' Cause: org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'lists' in 'class com.jt.springboot_demo3_mybatis.pojo.Dept'

原因、

        在 resultMap 里 collection 标签的 property 错误写为 “lists”

<collection property="lists" ofType="Emp" column="dept_id" select="findEmp"/>

解决方法、

        将 property = ”lists“ 改为 property = “emps“

<collection property="emps" ofType="Emp" column="dept_id" select="findEmp"/>

bug5、

提示、

        在xml文件使用子查询时没有dept 信息

[Emp(empId=1, empName=妲己, empAge=18, dept=null), Emp(empId=2, empName=貂蝉, empAge=19, dept=null)]

原因、

        在主查询中没有查询到关联字段 dept_id 以至于子查询的 where dept_id = #{dept_id} 无用

<select id="finAllEmpAndDept" resultMap="allEmpRM">
    select emp_id,emp_name,emp_age from emp
</select>

解决方法、

        在主查询中 查询到 表间关联字段

<select id="finAllEmpAndDept" resultMap="allEmpRM">
    select emp_id,emp_name,emp_age,dept_id from emp
</select>

SpringBoot  --  BUG 合集

bug1、

提示、

Field userMapper in com.jt.service.UserServiceImpl required a bean of type 'com.jt.mapper.UserMapper' that could not be found.

原因、

        UserMapper 接口没有交给 Spring 容器管理

解决方法、

        在UserMapper 接口上加 @Mapper 注解
  或  在启动类上加 @MapperScan("mapper类全路径") 注解

bug2、

提示、

2021-09-28 15:29:24.110 ERROR 9332 --- [nio-8090-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.jt.service.UserService.findAll] with root cause

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.jt.service.UserService.findAll

原因、

        在启动类上的的 @MapperScan 注解没写完整

解决方法、

@SpringBootApplication
//根据包扫描路径 扫描全部的mapper接口文件
@MapperScan("com.jt.mapper")
public class SpringbootSsmApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootSsmApplication.class, args);
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
0 1.txt 2012-06-11 11:00 76,093 178个经典c语言源代码.rar 2012-06-11 10:10 195 1小时后关机.bat 2012-06-11 10:10 68 1小时后关机.vbs 2012-06-11 09:51 105,472 30902382_高谦一-贪吃蛇游戏设计.doc 2012-06-11 09:59 232 79套经典网页设计模版.zip 2012-06-11 10:18 373,373 ADO数据组件精解示例.rar 2012-06-11 10:31 2,314,224 ArcGIS Engine开发从入门到精通源码.rar 2012-06-11 10:32 2,177,024 AS3游戏引擎框架大全(ZF).doc 2012-06-11 10:15 99,780 C++“超级玛丽”游戏的源代码.rar 2012-06-11 10:03 27,136 c++编写的增删改查.doc 2012-06-11 09:53 0 cpa自动注册工具源码.zip 2012-06-11 10:04 61,440 C_调用Win32_的API函数.doc 2012-05-21 16:18 10,581,941 dpcq.txt 2012-06-11 10:32 826,536 FFT的C语言算法实现.pdf 2012-06-11 10:23 5,249,485 hao123下载.rar 2012-06-11 10:25 1,274,074 IM_毕业设计.rar 2012-06-11 10:40 1,950 IP切换.txt 2012-06-11 10:20 1,081 Java获取CPU&主板&硬盘序列号.rar 2012-06-11 10:16 218,987 lexer2.zip 2012-06-11 10:00 0 matlab,格式化读写文件.rar 2012-06-11 10:29 296,867 matlab与vc溷合编程.pdf 2012-06-11 10:06 271,644 MATLAB图像处理与GUI设计篇.zip 2012-06-11 10:22 5,624,459 OpenGL游戏程序设计.zip 2012-06-11 10:14 369 QQ空间3d皮肤PSD源文件下载.rar 2012-06-11 09:45 110,869 RTDemo-获取串口数据并画出曲线图的VC++源码.7z 2012-06-11 11:21 4,352,443 TDDOWNLOAD.rar 2012-06-11 10:14 3,471,407 TFT浏览中文点阵字库.zip 2012-06-11 10:09 37,579 toolbar.zip 2012-06-11 10:05 2,506,416 uCOS-2 v290.rar 2012-06-11 10:12 377,168 uCOS-II多任务编程设计.pdf 2012-06-11 09:48 177 vb 非常漂亮的窗口源代码.rar 2012-06-11 09:52 1,322,177 VB图像处理一个例子.rar 2012-06-11 10:19 2,425,346 VB播放器源代码(播放SWF.MP3.RM文件等).rar 2012-06-11 10:28 0 VB远程桌面连接程序.rar 2012-06-11 10:41 6,630,010 VC俄罗斯方块.zip 2012-06-11 10:26 51,200 VHDL_六位加法器.doc 2012-06-11 10:39 3,519,250 WINTCV191双语版免费C语言编译器.zip 2012-06-

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值