MyBatis报错Parameter index out of range (1 > number of parameters, which is 0)

报错信息:
[ 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} %'  。

记录一下,长个记性。

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值