报错信息:
021-07-29 16:58:51.245 ERROR 22640 --- [nio-8080-exec-3] c.m.t.c.handler.GlobalExceptionHandler : exception:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
### The error may exist in com/mori/template/dao/mapper/OrdersMapper.java (best guess)
### The error may involve com.mori.template.dao.mapper.OrdersMapper.selectOne
### The error occurred while handling results
### SQL: SELECT order_number FROM orders WHERE deleted=0 AND (order_id = ?)
### Cause: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
调用信息:
Orders order = ordersMapper.selectOne(
Wrappers.<Orders>lambdaQuery()
.select(Orders::getOrderNumber)
.eq(Orders::getOrderId, id));
仅仅是使用了最简单的selectOne都会报错
原因:
实体类只使用了@Builder注解,@Builder注解使用后我们必须显示的声明构造方法,或者使用@AllArgsConstructor @NoArgsConstructor来声明构造。
这个异常正式因为使用MP和lombok不当造成的,mybatis找不到构造方法,无法将查询结果绑定到实体对象上~