Mabatis错误--Parameter index out of range
昨天遇到一个错误,之前也遇到过,但是之前遇到很快就解决了,昨天遇到这个错误当时看了大概10来分钟,还是没搞好,今天才来搞好了。
错误信息如下
- 08:34:43,302 DEBUG getTeachers:139 - ==> Preparing: SELECT a.*,b.classId,b.className FROM TeacherInfo a INNER JOIN ClassInfo b ON a.teacherId=b.teacherId
- 08:34:43,316 DEBUG NewPooledConnection:430 - com.mchange.v2.c3p0.impl.NewPooledConnection@2f187f handling a throwable.
- java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
- at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:959)
- at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
- at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
- at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:862)
- at com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3319)
- at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3304)
- at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3341)
- at com.mysql.jdbc.PreparedStatement.setNull(PreparedStatement.java:3380)
- at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.setNull(NewProxyPreparedStatement.java:157)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
- at java.lang.reflect.Method.invoke(Unknown Source)
- at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:70)
- at com.sun.proxy.$Proxy34.setNull(Unknown Source)
- at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:43)
- at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:81)
- at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:80)
- at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:61)
- at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:74)
- at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:59)
- at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
- at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)
- at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)
- at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77)
- at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)
- at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
- at java.lang.reflect.Method.invoke(Unknown Source)
- at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434)
- at com.sun.proxy.$Proxy15.selectList(Unknown Source)
- at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:231)
- at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:119)
- at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
- at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
- at com.sun.proxy.$Proxy20.getTeachers(Unknown Source)
- at com.taohan.online.exam.service.impl.TeacherInfoServiceImpl.getTeachers(TeacherInfoServiceImpl.java:59)
- at com.taohan.online.exam.handler.ClassInfoHandler.preUpdateClass(ClassInfoHandler.java:176)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
- at java.lang.reflect.Method.invoke(Unknown Source)
- at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)
- at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
- at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
- at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)
- at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)
- at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
- at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
- at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
- at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)
- at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:860)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
- at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
- at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
- at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
- at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
- at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
- at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
- at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
- at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
- at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
- at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
- at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
- at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
- at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
- at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
- at java.lang.Thread.run(Unknown Source)
- 08:34:43,319 DEBUG SqlUtils:85 - Attempted to convert SQLException to SQLException. Leaving it alone. [SQLState: S1009; errorCode: 0]
- java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
- at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:959)
- at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
- at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
- at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:862)
- at com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3319)
- at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3304)
- at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3341)
- at com.mysql.jdbc.PreparedStatement.setNull(PreparedStatement.java:3380)
- at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.setNull(NewProxyPreparedStatement.java:157)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
- at java.lang.reflect.Method.invoke(Unknown Source)
- at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:70)
- at com.sun.proxy.$Proxy34.setNull(Unknown Source)
- at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:43)
- at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:81)
- at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:80)
- at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:61)
- at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:74)
- at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:59)
- at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
- at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)
- at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)
- at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77)
- at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)
- at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
- at java.lang.reflect.Method.invoke(Unknown Source)
- at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434)
- at com.sun.proxy.$Proxy15.selectList(Unknown Source)
- at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:231)
- at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:119)
- at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
- at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
- at com.sun.proxy.$Proxy20.getTeachers(Unknown Source)
- at com.taohan.online.exam.service.impl.TeacherInfoServiceImpl.getTeachers(TeacherInfoServiceImpl.java:59)
- at com.taohan.online.exam.handler.ClassInfoHandler.preUpdateClass(ClassInfoHandler.java:176)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
- at java.lang.reflect.Method.invoke(Unknown Source)
- at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)
- at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
- at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
- at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)
- at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)
- at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
- at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
- at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
- at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)
- at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:860)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
- at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
- at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
- at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
- at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
- at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
- at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
- at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
- at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
- at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
- at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
- at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
- at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
- at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
- at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
- at java.lang.Thread.run(Unknown Source)
- 08:34:43,320 DEBUG DefaultConnectionTester:126 - Testing a Connection in response to an Exception:
- java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
- at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:959)
- at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
- at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
- at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:862)
- at com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3319)
- at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3304)
- at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3341)
- at com.mysql.jdbc.PreparedStatement.setNull(PreparedStatement.java:3380)
- at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.setNull(NewProxyPreparedStatement.java:157)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
- at java.lang.reflect.Method.invoke(Unknown Source)
- at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:70)
- at com.sun.proxy.$Proxy34.setNull(Unknown Source)
- at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:43)
- at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:81)
- at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:80)
- at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:61)
- at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:74)
- at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:59)
- at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
- at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)
- at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)
- at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77)
- at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)
- at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
- at java.lang.reflect.Method.invoke(Unknown Source)
- at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434)
- at com.sun.proxy.$Proxy15.selectList(Unknown Source)
- at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:231)
- at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:119)
- at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
- at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
- at com.sun.proxy.$Proxy20.getTeachers(Unknown Source)
- at com.taohan.online.exam.service.impl.TeacherInfoServiceImpl.getTeachers(TeacherInfoServiceImpl.java:59)
- at com.taohan.online.exam.handler.ClassInfoHandler.preUpdateClass(ClassInfoHandler.java:176)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
- at java.lang.reflect.Method.invoke(Unknown Source)
- at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)
- at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
- at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
- at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)
- at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)
- at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
- at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
- at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
- at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)
- at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:860)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
- at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
- at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
- at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
- at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
- at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
- at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
- at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
- at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
- at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
- at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
- at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
- at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
- at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
- at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
- at java.lang.Thread.run(Unknown Source)
错误描述
错误信息关键描述
- Parameter index out of range (1 > number of parameters, which is 0)
反正就是说我的参数存在问题
业务代码描述
修改班级信息时可以修改班级对应班主任,所以需要查询出对应的非班主任教师。
Handler
- @RequestMapping(value="edit/class/{classId}", method=RequestMethod.GET)
- public ModelAndView preUpdateClass(@PathVariable("classId") Integer classId) {
- logger.info("预修改班级处理");
- ModelAndView model = new ModelAndView();
- //获取要修改班级
- ClassInfo classInfo = classInfoService.getClassById(classId);
- model.setViewName("/admin/classedit");
- model.addObject("editClass", classInfo);
- List<GradeInfo> grades = gradeInfoService.getGrades();
- //获取不是班主任的教师
- teacher.setIsWork(0); // isWork为0就不是班主任
- List<TeacherInfo> 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);
- return model;
- }
映射文件
Statement会接收一个 Map 集合
- <resultMap type="com.taohan.online.exam.po.TeacherInfo" id="getTeacherResultMap">
- <id column="teacherId" property="teacherId"/>
- <result column="teacherName" property="teacherName" />
- <result column="teacherAccount" property="teacherAccount"/>
- <result column="teacherPwd" property="teacherPwd"/>
- <result column="adminPower" property="adminPower"/>
- <result column="isWork" property="isWork"/>
- <association property="classInfo" javaType="com.taohan.online.exam.po.ClassInfo">
- <id column="classId" property="classId"/>
- <result column="className" property="className"/>
- </association>
- </resultMap>
- <parameterMap type="java.util.Map" id="getTeachersParameterMap">
- <!-- 教师对象 -->
- <parameter property="teacher" resultMap="getTeacherResultMap"/>
- <!-- 起始位置索引 -->
- <parameter property="startIndex" resultMap="getTeacherResultMap"/>
- <!-- 每页显示数据量 -->
- <parameter property="pageShow" resultMap="getTeacherResultMap"/>
- </parameterMap>
- <!-- 使用 paramenterMap 查询 -->
- <select id="getTeachers" parameterMap="getTeachersParameterMap" resultMap="getTeacherResultMap">
- SELECT a.*,b.classId,b.className FROM TeacherInfo a
- INNER JOIN ClassInfo b ON a.teacherId=b.teacherId
<!--
getTeachers()方法我传入的是 null,那么,在下面进行条件判断的时候并不能找到 teacher、startIndex、pageShow,所以抛出异常
-->- <where>
- <if test="teacher != null">
- isWork=#{teacher.isWork}
- </if>
- </where>
- <if test="startIndex != null and pageShow != null">
- LIMIT #{startIndex}, #{pageShow}
- </if>
- </select>
总结
通过之前犯过类似的错误,以及这次错误,我发现 今后只要是 Parameter index out of range (1 > number of parameters, which is 0) 类似的错误大致定位在 映射文件和调用方法传入参数,
映射文件
如果使用了 parameterMap, resultMap,或是返回集合,就要检查参数名称和属性名称是否一致
调用方法
针对使用了 parameterMap 或 parameterType,需要检查传入Map中的键是否存在、匹配,或传入对象是否存在指定属性
Mabatis错误--Parameter index out of range的更多相关文章
- Parameter index out of range (2 > number of parameters, which is 1)
今天在实现一个功能时遇到一个问题,解决了很久.结果是#{}与${}使用错误的原因.但是具体原因还不是很清楚,写此篇总结,知道的可以交流. 具体描述为:通过教师的头衔(1高级讲师2首席讲师)及名称进行模 ...
- Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0
1.错误描述 [ERROR:]2015-05-05 16:35:50,664 [异常拦截] org.hibernate.exception.GenericJDBCException: error ex ...
- mybatis中Parameter index out of range (1 > number of parameters, which is 0).
Parameter index out of range (1 > number of parameters, which is 0).(参数索引超出范围) 在mybatis里面写就是应该是 l ...
- java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2).
java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2). java. ...
- [转]操作MySQL数据库报出:Parameter index out of range (1 > number of parameters, which is
原文地址:https://blog.csdn.net/zdx_y/article/details/52072914 对MySQL进行insert操作,控制台抛出以下错误:Parameter index ...
- Parameter index out of range (1 > number of parameters, which is 0).
数据库错误:Parameter index out of range (1 > number of parameters, which is 0) ...
- Parameter index out of range(1 > number of parameters, which is 0)参数索引超出范围
今天在写项目的过程中,有一个模块是做多选删除操作,通过servlet获得多选框的value组,然后执行sql操作.如下: 1 @RequestMapping( "/delteCouse.do ...
- java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0). at co ...
- IDEA_MyBatis_SQLException:Parameter index out of range坑
报错信息:超出数据库数据表设定的规定长度了 nested exception is org.apache.ibatis.type.TypeException: Could not set parame ...
随机推荐
- python tkinter窗口置顶
下面两句即可实现root窗口的置顶显示,可以用于某些程序的消息提示,能够弹出到桌面显示 root = Tk()root.wm_attributes('-topmost',1)
- JavaScript01天学习笔记分享
01知识点 JavaScript 代码运行在浏览器(后缀名.js) 和java完全不同的东西,只是名称类型而已 src 引用脚本 <Script></Script> ale ...
- CSS动画持续汇总中
一:向上的动态箭头------------------http://www.5599.com/88lz/up_direct.html
- Install-Package : “XXXX”已拥有为“XXXX”定义的依赖项。
Install-Package : “AutoMapper”已拥有为“NETStandard.Library”定义的依赖项.所在位置 行:1 字符: 16+ Install-Package <& ...
- 17 C#中的循环执行 while循环
在编程中有代码的执行主要有三种方式.(1)顺序执行,也就是一条语句一条语句按顺序执行:(2)条件执行,也就是if...else.当某种条件满足时执行一些代码:(3)循环执行,就是当某种条件满足的时候, ...
- Hadoop的数据采集框架
问题导读: Hadoop数据采集框架都有哪些? Hadoop数据采集框架异同及适用场景? Hadoop提供了一个高度容错的分布式存储系统,帮助我们实现集中式的数据分析和数据共享.在日常应用中我们比如要 ...
- [ 东莞市选 2008 ] GCD&LCM
\(\\\) \(Description\) 给出两数的\(GCD\)和\(LCM\),求合法的两数之差的绝对值最小是多少. \(GCD\times LCM\le10^{18}\) \(\\\) \( ...
- 如何取消android studio启动时自动打开上次关闭的项目
Androidstudio默认每次android studio启动就会自动打开上次关闭的项目,如果想要取消并让它显示此界面 只需要
- MySql 1248 - Every derived table must have its own alias
执行一个sql语句,报错:1248 - Every derived table must have its own alias 提示说每一个衍生出来的表,必须要有自己的别名 执行子查询的时候,外层查询 ...
- POJ_1847_Tram
Tram Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 11159 Accepted: 4089 Description ...