mapper xml 查询时报错
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 file [C:\Users\56342\Desktop\irest\irest-reports\irest-reports-server\target\classes\com\shht\irest\reports\server\mapper\oms\xml\OrderTransactionMapper.xml]
### The error may involve com.shht.irest.reports.server.mapper.oms.OrderTransactionMapper.countConsumeCount
### The error occurred while handling results
### SQL: SELECT COUNT(DISTINCT(ot.id)) as `count` FROM oms_order_transaction ot JOIN oms_order_transaction_detail otd ON ot.id = otd.transaction_id WHERE ot.tenant_id = 1 AND ot.pay_time BETWEEN ? AND ? AND ot.type = 'CONSUME' and ot.state = 'SUCCESS' AND ot.delete_flag = 0 AND otd.merchant_id = ?
### Cause: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:92)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440)
at com.sun.proxy.$Proxy124.selectOne(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:159)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:90)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89)
at com.sun.proxy.$Proxy128.countConsumeCount(Unknown Source)
对应的sql 语句
select
dispute.case_type caseType,
zhuandi.create_time createTime,
zhuandi.dispute_id disputeId,
zhuandi.innertdeptcode,
zhuandi.innertdept,
zhuandi.zhuandi_status zhuandiStatus,
'' zhuandiStatusTxt,
zhuandi.zddwcode,
zhuandi.zddw,
dispute.case_time caseTime,
dispute.case_address caseAddress,
dispute.case_person casePerson,
dispute.case_phone casePhone,
dispute.case_content caseContent,
dispute.case_code caseCode,
dispute.parent_region_name parentRegionName,
dispute.region_name regionName,
dispute.region_code regionCode,
dispute.zrqmc,
dispute.zrqdm,
dispute.pcsdm,
dispute.pcsmc,
dispute.cszrqmc,
dispute.cszrqdm
FROM dispute_forward zhuandi
LEFT JOIN dispute on dispute.id=zhuandi.dispute_id and dispute.del_flag=0 and zhuandi.deleted=0
WHERE 1=1 AND zhuandi.zhuandi_lx = '1'
<if test="startTime != null and startTime != ''">
AND zhuandi.create_time >= #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND zhuandi.create_time <= #{endTime}
</if>
<if test="zrqdm != null and zrqdm != ''">
and zhuandi.innertdeptcode like concat(#{zrqdm}, '%')
</if>
<if test="zhuandiStatus != null and zhuandiStatus != ''">
and zhuandi.zhuandi_status = #{zhuandiStatus}
</if>
<if test="caseCode != null and caseCode != ''">
AND case_code like concat( '%',#{caseCode}, '%')
</if>
<if test="casePhone != null and casePhone != ''">
AND case_phone like concat('%',#{casePhone}, '%')
</if>
<if test="casePerson != null and casePerson != ''">
AND case_person like concat('%',#{casePerson}, '%')
</if>
<if test="caseAddress != null and caseAddress != ''">
AND case_address like concat('%',#{caseAddress}, '%')
</if>
AND zhuandi.zhuandi_status in (0,1)
order by zhuandi.create_time desc
出现场景:在使用MyBatis进行SQL查询的时候,会抛出异常java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
出现原因:项目中Mapper查询结果映射的Result实体类没有提供无参构造器
解决方法:映射的实体类加上@NoArgsConstructor
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DisputeZhuanDiVO
{
}