先看报错信息:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Failed to process, Error SQL: SELECT count(*) FROM m_work_order_plan mp
    where mp.work_status = 1
    and mp.actual_end_time between ? and ?
            and mp.executor_id in

通过debug和数据追源发现 不应该拼接 and mp.executor_id in

排查到问题代码 集合判断失败导致拼接多余代码

问题代码:

<if test="dto.executorIds !=null and dto.executorIds!=''">
   and mp.executor_id in
   <foreach collection="dto.executorIds" item="executorId" index="i" open="(" close=")" separator=",">
      #{executorId}
   </foreach>

修正后:

<if test="dto.executorIds !=null and dto.executorIds.size>0">
   and mp.executor_id in
   <foreach collection="dto.executorIds" item="executorId" index="i" open="(" close=")" separator=",">
      #{executorId}
   </foreach>
</if>

问题出现原因:

数组判空问题

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐