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  //无参构造函数
  • 30
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值