MybatisPlus出现Error querying database. Cause: java.lang.IndexOutOfBoundsException: Index: 7, Size: 7

问题

今天在项目中遇到一个问题:项目中使用了mybatisplus和lombok,在执行查询操作时,后台报错:

2020-03-20 19:48:26.232 ERROR 11612 --- [nio-8000-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.IndexOutOfBoundsException: Index: 7, Size: 7
### The error may exist in com/foxconn/mapper/UserMapper.java (best guess)
### The error may involve com.foxconn.mapper.UserMapper.selectOne
### The error occurred while handling results
### SQL: SELECT   openid,nick_name,real_name,identity_card,email,birth,mobile   FROM user     WHERE (openid = ? AND status = ?)
### Cause: java.lang.IndexOutOfBoundsException: Index: 7, Size: 7] with root cause

分析

从上面可以看打印的sql日志,发现mybatisplus生成的sql是没问题的,于是怀疑是参数传递出错,分析了一下程序:

 QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.select("openid", "nick_name", "real_name", "identity_card", "email", "birth", "mobile")
        .eq("openid", openid).eq("status", "0");
        User user = userService.getOne(wrapper);

深思熟虑后这段代码是没问题的,最后只能怀疑到实体类上了,查看实体类User,我这里使用了lombok插件,检查了idea安装了插件,maven也导入了依赖包。
在这里插入图片描述
最终测试发现实体类并没有提供构造函数,@Data并不能自动生成构造函数,查了资料,在类似添加了两个构造函数注解,问题解决。

@Data
@Builder
@AllArgsConstructor //全参构造函数
@NoArgsConstructor  //无参构造函数
我在使用mp的分页,原先功能可以正常使用,机器重启后报了如下错误2023-06-02 14:15:54.169 ERROR --- [nio-8890-exec-5] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 ### Cause: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0] with root cause java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.rangeCheck(ArrayList.java:657) at java.util.ArrayList.get(ArrayList.java:433) at com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor.willDoQuery(PaginationInnerInterceptor.java:134) at com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.intercept(MybatisPlusInterceptor.java:59) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) at com.sun.proxy.$Proxy76.query(Unknown Source) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) at sun.reflect.GeneratedMethodAccessor68.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426) at com.sun.proxy.$Proxy58.selectList(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:223) at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForIPage(MybatisMapperMethod.java:122) at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:87) at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(Mybat
06-03
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值