Mabatis错误提示Parameter index out of range的处理方法

这个问题把小编急毁了,捣腾了好几天还没有结果出来,今天终于捣腾出来了,下面小编把经过分享给大家,大家多多提出宝贵意见。

错误信息如下

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中的键是否存在、匹配,或传入对象是否存在指定属性

下面看下在数据库中遇到Parameter index out of range  错误该如何处理?

最近学ssm框架的时候,遇到了这个错误,找了半天的原因,最后发现原来是sql语句中多了一对单引号。传入值的类型为String类型,就以为还要加引号以表示传入的是字符串,其实是错的,还是初学对其还不太了解。

如下:

错误的:

<update id="updateState" parameterType="java.lang.String">
   UPDATE login SET State = 0 WHERE LID = '#{value}'
</update>

正确的:

<update id="updateState" parameterType="java.lang.String">
   UPDATE login SET State = 0 WHERE LID = #{value}
</update>

以上所述是小编给大家介绍的Mabatis错误提示Parameter index out of range的处理方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对我们网站的支持!

(0)

相关推荐

  • MyBatis绑定错误提示BindingException:Invalid bound statement (not found)的解决方法

    如果出现: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 一般的原因是Mapper interface和xml文件的定义对应不上,需要检查包名,namespace,函数名称等能否对应上. 按以下步骤一一执行: 1.检查xml文件所在的package名称是否和interface对应的package名称一一对应 2.检查xml文件的namespace是否和xml文件的package名称一

  • spring boot启动时mybatis报循环依赖的错误(推荐)

    自己在做项目时,想使用热部署减少部署时间,于是添加了springboot-devtools 在maven中添加了依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency> 然后正常的启动项目时发现控制台一直在不停的输出错误,错误如图 不明所以,然后就准备去调

  • Mabatis错误提示Parameter index out of range的处理方法

    这个问题把小编急毁了,捣腾了好几天还没有结果出来,今天终于捣腾出来了,下面小编把经过分享给大家,大家多多提出宝贵意见. 错误信息如下 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 NewPooledC

  • Java String index out of range:100错误解决方案详解

    问题出错情况:字符串截取长度,没有那么长的长度所以截取失败. 在这里进行debug之后可以看到,异常在substring中: 也就是判断字符串的时候报错:具体原因就是string字符串indexof的值本身只有5,然后在这里去取其第100 个字符作为截止,因此就会报这个错: 知识点:主要是堆String概念不清.下面针对字符串相关概念做一个简介. 针对上述问题解决办法: 到此这篇关于Java String index out of range:100错误解决方案详解的文章就介绍到这了,更多相关J

  • Mybatis批量插入index out of range错误的解决(较偏的错误)

    目录 Mybatis批量插入index out of range错误 原因 改进 String index out of range: 100 报错详解 一个很奇葩的报错,出错情况 知识点 针对上述问题解决办法 Mybatis批量插入index out of range错误 往往我们看到网上关于各类关于批量插入报这种错误的文章都是传入的集合为null,或者是参数获取不对等等,但是在开发的时候同事遇到了这种类型的错误,我一直以为是网上那些博客那些原因造成的,于是,两只眼睛一直盯着代码看来许久都没有

  • PHP 中提示undefined index如何解决(多种方法)

    一.相关信息 平时用$_post['']或$_get['']获取表单中参数时会出现Notice: Undefined index: --------: 以及我们经常接收表单POST过来的数据时报Undefined index错误 例如:$act=$_POST['action'];使用以上代码总是会提示Notice: Undefined index: act in D:\test\post.php on line 20另外,有时还会出现Notice: Undefined variable: Sub

  • Codeigniter中禁止A Database Error Occurred错误提示的方法

    在默认的情况下,CodeIgniter会显示所有的PHP错误.但是当你开发程序结束时,你可能想要改变这个情况.你会发现在index.php文件顶端有这个函数error_reporting(),通过它可以进行对错误的设置. 即使你关闭了错误报告,当有错误发生时,错误记录也不会停止.所以,修改php.ini不能达到我们想要的效果. 下面是解决办法: 1. Codeigniter中禁止A Database Error Occurred错误提示 在CodeIgniter 用户指南中说到,设置 ENVIR

  • PHP常见的6个错误提示及解决方法

    在php开发过程中,由于不知道向谁求助而心慌意乱地判断以为自己不适合学php.其实错误在每个人学习过程中都会碰到的,千万不要妄自菲薄.很多错误在报错的代码提示中已经告诉我们了,仔细看,不会就百度.现总结一些常见的php错误,以共享php新人. Php常见错误提示 一.Fatal error: Call to undefined function-- 函数不存在,可能的原因: 1.系统不存在这个函数且你也没自定义 2.有人会问,我在别的机器上就不报错.那是因为环境不同,这个函数在本机没开,怎么开?

  • PHP常见错误提示含义解释(实用!值得收藏)

    本文讲述了PHP常见错误提示含义解释.分享给大家供大家参考,具体如下: 在学习PHP的时候,经常遇到各种错误提示,今天看到这错误提示和解释感觉挺好,现转过来,供我们学习.呵呵..... 1.Notice: Undefined variable:  变量名 in 注:使用了一个没有被定义的变量 2.Parse error: syntax error, unexpected T_ELSE in  If () { }Else if () { } Echo $test; Else { } 注:是 if

  • Laravel解决nesting level错误和隐藏index.php的问题

    错误提示:Maximum function nesting level of '100' reached, aborting! 解决办法:因为我是在windows上搭建的wamp环境,linux和mac暂时还没有实验,首先找到php.ini找到xdebug项,在最后添加一行xdebug.max_nesting_level=500 那么laravel如何隐藏index.php呢? 首先进入public文件夹建立.htaccess文件,写入 <IfModule mod_rewrite.c> Opt

  • nuxt.js写项目时增加错误提示页面操作

    为项目增加错误提示页面,比如后端接口没有数据或接口报错的时候,如果不增加错误提示页面的话,那接口报错的信息就会在页面中显示,这显然不利于用户体验. 实际操作过程中,可能因为各种原因无法显示正确的返回页面,比如本身这篇文章的id不存在,或者网络请求问题,这时候就需要一个错误展示页用来提示用户: nuxt.js官方也有错误提示页面的写法:传送门-> 官方错误提示页面的写法 此项目中的错误提示页面是放在layouts目录中: layouts中的error.vue页面内容为: <template>

  • 上传IPA出现的错误提示“application loader“上传出错解决方法

    上传IPA出现的错误提示"application loader"上传出错解决方法 使用Application Loader 上传ipa出现的错误提示"application loader上传出错 生成的API分析文件太大"解决方法 如下图: 解决办法就是修改Xcode里面的这里写 因为之前上传的时候有使用过的Build号,只需要修改一下就好 感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

随机推荐