报错信息:
[ WARN] [batch] 2019-07-26 14:09:15: 135435 [WARN ] [http-apr-8080-exec-1] ( AbstractHandlerExceptionResolver.java,189 ) - Handler execution resulted in exception:
### Error querying database. Cause: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
### The error may exist in file [E:\Project\Project02\src\main\webapp\WEB-INF\classes\com\kcppc\weekplan\mapper\sqlmap\TWeekPlanInfoMapper.xml]
### The error may involve com.kcppc.weekplan.mapper.TWeekPlanInfoMapper.selectOverdueTask-Inline
### The error occurred while setting parameters
### SQL: SELECT t_week_plan_info.*, sys_user_info.user_id as userName, sys_organization.name as deptName, case task_level when '0' then '个人任务' when '1' then '部组任务' else '公司任务' end as taskLevelName, case completed_state when '0' then '未启动 待执行计划' when '1' then '进行中' when '2' then '已完成' else '未完成,逾期' end as completedStateName, case task_type when '1' then '新客户开发' when '2' then '政策整理' when '3' then '合同签订' else '软著申报' end as taskTypeName, case case_type when '1' then '发明' when '2' then '实用新型' when '3' then '外观设计' when '4' then '发明(双报)' else '实用新型(双报)' end as caseTypeName, case submit_status when '0' then '未提交' when '1' then '提交到部门' else '提交到公司' end as submitStatusName from t_week_plan_info LEFT JOIN sys_user_info on sys_user_info.id = t_week_plan_info.user_id LEFT JOIN sys_organization on sys_organization.tree_id = t_week_plan_info.dept_id where t_week_plan_info.completed_state = 3 and sys_user_info.user_id like '%?%'
### Cause: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
; SQL []; Parameter index out of range (1 > number of parameters, which is 0).; nested exception is java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
[DEBUG] [batch] 2019-07-26 14:09:15: 135435 [DEBUG] [http-apr-8080-exec-1] ( DispatcherServlet.java,1034 ) - Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling
[DEBUG] [batch] 2019-07-26 14:09:15: 135436 [DEBUG] [http-apr-8080-exec-1] ( FrameworkServlet.java,1000 ) - Successfully completed request
[DEBUG] [batch] 2019-07-26 14:09:15: 135436 [DEBUG] [http-apr-8080-exec-1] ( AbstractBeanFactory.java,250 ) - Returning cached instance of singleton bean 'sqlSessionFactory'
原因是在Sql中使用like语句查询时用了
and sys_organization.name like '%#{deptName}%'
应该用
and sys_organization.name like '%${deptName}%'
在MyBatis中select ... like 用 '%${name} %' 而不是 '%#{name} %' 。
记录一下,长个记性。