Mabatis错误提示Parameter index out of range的处理方法
这个问题把小编急毁了,捣腾了好几天还没有结果出来,今天终于捣腾出来了,下面小编把经过分享给大家,大家多多提出宝贵意见。
错误信息如下
08:34:43,302DEBUGgetTeachers:139-==>Preparing:SELECTa.*,b.classId,b.classNameFROMTeacherInfoaINNERJOINClassInfobONa.teacherId=b.teacherId 08:34:43,316DEBUGNewPooledConnection:430-com.mchange.v2.c3p0.impl.NewPooledConnection@2f187fhandlingathrowable. java.sql.SQLException:Parameterindexoutofrange(1>numberofparameters,whichis0). atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:959) atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:898) atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:887) atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:862) atcom.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3319) atcom.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3304) atcom.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3341) atcom.mysql.jdbc.PreparedStatement.setNull(PreparedStatement.java:3380) atcom.mchange.v2.c3p0.impl.NewProxyPreparedStatement.setNull(NewProxyPreparedStatement.java:157) atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod) atsun.reflect.NativeMethodAccessorImpl.invoke(UnknownSource) atsun.reflect.DelegatingMethodAccessorImpl.invoke(UnknownSource) atjava.lang.reflect.Method.invoke(UnknownSource) atorg.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:70) atcom.sun.proxy.$Proxy34.setNull(UnknownSource) atorg.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:43) atorg.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:81) atorg.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:80) atorg.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:61) atorg.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:74) atorg.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:59) atorg.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267) atorg.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137) atorg.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96) atorg.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77) atorg.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108) atorg.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102) atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod) atsun.reflect.NativeMethodAccessorImpl.invoke(UnknownSource) atsun.reflect.DelegatingMethodAccessorImpl.invoke(UnknownSource) atjava.lang.reflect.Method.invoke(UnknownSource) atorg.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434) atcom.sun.proxy.$Proxy15.selectList(UnknownSource) atorg.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:231) atorg.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:119) atorg.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63) atorg.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52) atcom.sun.proxy.$Proxy20.getTeachers(UnknownSource) atcom.taohan.online.exam.service.impl.TeacherInfoServiceImpl.getTeachers(TeacherInfoServiceImpl.java:59) atcom.taohan.online.exam.handler.ClassInfoHandler.preUpdateClass(ClassInfoHandler.java:176) atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod) atsun.reflect.NativeMethodAccessorImpl.invoke(UnknownSource) atsun.reflect.DelegatingMethodAccessorImpl.invoke(UnknownSource) atjava.lang.reflect.Method.invoke(UnknownSource) atorg.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222) atorg.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) atorg.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) atorg.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814) atorg.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737) atorg.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) atorg.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) atorg.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) atorg.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969) atorg.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:860) atjavax.servlet.http.HttpServlet.service(HttpServlet.java:617) atorg.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845) atjavax.servlet.http.HttpServlet.service(HttpServlet.java:717) atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) atorg.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) atorg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) atorg.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121) atorg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) atorg.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857) atorg.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) atorg.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) atjava.lang.Thread.run(UnknownSource) 08:34:43,319DEBUGSqlUtils:85-AttemptedtoconvertSQLExceptiontoSQLException.Leavingitalone.[SQLState:S1009;errorCode:0] java.sql.SQLException:Parameterindexoutofrange(1>numberofparameters,whichis0). atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:959) atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:898) atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:887) atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:862) atcom.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3319) atcom.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3304) atcom.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3341) atcom.mysql.jdbc.PreparedStatement.setNull(PreparedStatement.java:3380) atcom.mchange.v2.c3p0.impl.NewProxyPreparedStatement.setNull(NewProxyPreparedStatement.java:157) atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod) atsun.reflect.NativeMethodAccessorImpl.invoke(UnknownSource) atsun.reflect.DelegatingMethodAccessorImpl.invoke(UnknownSource) atjava.lang.reflect.Method.invoke(UnknownSource) atorg.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:70) atcom.sun.proxy.$Proxy34.setNull(UnknownSource) atorg.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:43) atorg.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:81) atorg.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:80) atorg.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:61) atorg.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:74) atorg.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:59) atorg.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267) atorg.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137) atorg.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96) atorg.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77) atorg.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108) atorg.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102) atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod) atsun.reflect.NativeMethodAccessorImpl.invoke(UnknownSource) atsun.reflect.DelegatingMethodAccessorImpl.invoke(UnknownSource) atjava.lang.reflect.Method.invoke(UnknownSource) atorg.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434) atcom.sun.proxy.$Proxy15.selectList(UnknownSource) atorg.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:231) atorg.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:119) atorg.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63) atorg.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52) atcom.sun.proxy.$Proxy20.getTeachers(UnknownSource) atcom.taohan.online.exam.service.impl.TeacherInfoServiceImpl.getTeachers(TeacherInfoServiceImpl.java:59) atcom.taohan.online.exam.handler.ClassInfoHandler.preUpdateClass(ClassInfoHandler.java:176) atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod) atsun.reflect.NativeMethodAccessorImpl.invoke(UnknownSource) atsun.reflect.DelegatingMethodAccessorImpl.invoke(UnknownSource) atjava.lang.reflect.Method.invoke(UnknownSource) atorg.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222) atorg.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) atorg.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) atorg.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814) atorg.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737) atorg.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) atorg.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) atorg.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) atorg.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969) atorg.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:860) atjavax.servlet.http.HttpServlet.service(HttpServlet.java:617) atorg.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845) atjavax.servlet.http.HttpServlet.service(HttpServlet.java:717) atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) atorg.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) atorg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) atorg.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121) atorg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) atorg.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857) atorg.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) atorg.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) atjava.lang.Thread.run(UnknownSource) 08:34:43,320DEBUGDefaultConnectionTester:126-TestingaConnectioninresponsetoanException: java.sql.SQLException:Parameterindexoutofrange(1>numberofparameters,whichis0). atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:959) atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:898) atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:887) atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:862) atcom.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3319) atcom.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3304) atcom.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3341) atcom.mysql.jdbc.PreparedStatement.setNull(PreparedStatement.java:3380) atcom.mchange.v2.c3p0.impl.NewProxyPreparedStatement.setNull(NewProxyPreparedStatement.java:157) atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod) atsun.reflect.NativeMethodAccessorImpl.invoke(UnknownSource) atsun.reflect.DelegatingMethodAccessorImpl.invoke(UnknownSource) atjava.lang.reflect.Method.invoke(UnknownSource) atorg.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:70) atcom.sun.proxy.$Proxy34.setNull(UnknownSource) atorg.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:43) atorg.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:81) atorg.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:80) atorg.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:61) atorg.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:74) atorg.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:59) atorg.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267) atorg.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137) atorg.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96) atorg.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77) atorg.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108) atorg.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102) atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod) atsun.reflect.NativeMethodAccessorImpl.invoke(UnknownSource) atsun.reflect.DelegatingMethodAccessorImpl.invoke(UnknownSource) atjava.lang.reflect.Method.invoke(UnknownSource) atorg.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434) atcom.sun.proxy.$Proxy15.selectList(UnknownSource) atorg.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:231) atorg.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:119) atorg.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63) atorg.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52) atcom.sun.proxy.$Proxy20.getTeachers(UnknownSource) atcom.taohan.online.exam.service.impl.TeacherInfoServiceImpl.getTeachers(TeacherInfoServiceImpl.java:59) atcom.taohan.online.exam.handler.ClassInfoHandler.preUpdateClass(ClassInfoHandler.java:176) atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod) atsun.reflect.NativeMethodAccessorImpl.invoke(UnknownSource) atsun.reflect.DelegatingMethodAccessorImpl.invoke(UnknownSource) atjava.lang.reflect.Method.invoke(UnknownSource) atorg.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222) atorg.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) atorg.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) atorg.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814) atorg.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737) atorg.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) atorg.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) atorg.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) atorg.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969) atorg.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:860) atjavax.servlet.http.HttpServlet.service(HttpServlet.java:617) atorg.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845) atjavax.servlet.http.HttpServlet.service(HttpServlet.java:717) atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) atorg.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) atorg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) atorg.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121) atorg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) atorg.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857) atorg.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) atorg.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) atjava.lang.Thread.run(UnknownSource)
错误信息关键描述
Parameterindexoutofrange(1>numberofparameters,whichis0)
反正就是说我的参数存在问题
业务代码描述
修改班级信息时可以修改班级对应班主任,所以需要查询出对应的非班主任教师。
Handler
@RequestMapping(value="edit/class/{classId}",method=RequestMethod.GET) publicModelAndViewpreUpdateClass(@PathVariable("classId")IntegerclassId){ logger.info("预修改班级处理"); ModelAndViewmodel=newModelAndView(); //获取要修改班级 ClassInfoclassInfo=classInfoService.getClassById(classId); model.setViewName("/admin/classedit"); model.addObject("editClass",classInfo); Listgrades=gradeInfoService.getGrades(); //获取不是班主任的教师 teacher.setIsWork(0);//isWork为0就不是班主任 List teachers=teacherInfoService.getTeachers(null);//通过下面配置文件可知,该方法需要传入一个Map集合,而我这里传入一个null //如果没有可用班主任 if(teachers.size()==0||teachers==null){ teacher.setTeacherId(classInfo.getTeacher().getTeacherId()); teacher.setTeacherName("暂无剩余教师"); teachers.add(teacher); } model.addObject("teachers",teachers); model.addObject("grades",grades); returnmodel; }
映射文件
Statement会接收一个Map集合
SELECTa.*,b.classId,b.classNameFROMTeacherInfoa INNERJOINClassInfobONa.teacherId=b.teacherId isWork=#{teacher.isWork} LIMIT#{startIndex},#{pageShow}
总结
通过之前犯过类似的错误,以及这次错误,我发现今后只要是Parameterindexoutofrange(1>numberofparameters,whichis0)类似的错误大致定位在映射文件和调用方法传入参数,
映射文件
如果使用了parameterMap,resultMap,或是返回集合,就要检查参数名称和属性名称是否一致
调用方法
针对使用了parameterMap或parameterType,需要检查传入Map中的键是否存在、匹配,或传入对象是否存在指定属性
下面看下在数据库中遇到Parameterindexoutofrange 错误该如何处理?
最近学ssm框架的时候,遇到了这个错误,找了半天的原因,最后发现原来是sql语句中多了一对单引号。传入值的类型为String类型,就以为还要加引号以表示传入的是字符串,其实是错的,还是初学对其还不太了解。
如下:
错误的:
UPDATEloginSETState=0WHERELID='#{value}'
正确的:
UPDATEloginSETState=0WHERELID=#{value}
以上所述是小编给大家介绍的Mabatis错误提示Parameterindexoutofrange的处理方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。