sql单独执行正确,但是mybatis查询报错,部分错误信息如下:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
###Error querying database. Cause: java.lang.IndexOutOfBoundsException: Index: 6, Size: 6
###The error may involve com.xxx.persistence.mapper.XXXMapper.countxxxQty
###The error occurred while handling results
###SQL: SELECT D.WAREHOUSE_ID, D.SKU_ID, D.EXPECTED_QTY_NUM, D.NAME, D.OPER,D.OPER_TIME FROM do_header D WHERE D .do_type = 100 and D.sku_id in ( ? , ? , ? , ? )
###Cause: java.lang.IndexOutOfBoundsException: Index: 6, Size: 6
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:92)
at org.mybatis.spring.SqlSessionTemplate
S
q
l
S
e
s
s
i
o
n
I
n
t
e
r
c
e
p
t
o
r
.
i
n
v
o
k
e
(
S
q
l
S
e
s
s
i
o
n
T
e
m
p
l
a
t
e
.
j
a
v
a
:
440
)
a
t
c
o
m
.
s
u
n
.
p
r
o
x
y
.
SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440) at com.sun.proxy.
SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440)atcom.sun.proxy.Proxy106.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:223)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:93)
at com.sun.proxy.$Proxy241.countSkuQtyForCalculate(Unknown Source)
原因:
mapper中查询结果resultMap对应的DoxxxDto使用了lombok注解,使用有误导致的
。报错时的注解:
@Data
@Builder
public class DoxxxDto{
private xxx1;
private xxx2;
private xxx3;
private xxx4;
private xxx5;
private xxx6;
private xxx7;
}
没有构造函数,将查询结果转换成javebean的时候出了问题,报错中的6是因为查询了6列。加上构造函数的注解即可。如下:
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DoxxxDto{
private xxx1;
private xxx2;
private xxx3;
private xxx4;
private xxx5;
private xxx6;
private xxx7;
}
参考博客地址:https://blog.csdn.net/qq_37186947/article/details/102160260