欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Mabatis错误--Parameter index out of range

程序员文章站 2022-04-04 15:18:58
昨天遇到一个错误,之前也遇到过,但是之前遇到很快就解决了,昨天遇到这个错误当时看了大概10来分钟,还是没搞好,今天才来搞好了。 错误信息如下 08:34:43,302 DEBUG getTeachers:139 - ==> Preparing: SELECT a.*,b.classId,b.clas ......

  昨天遇到一个错误,之前也遇到过,但是之前遇到很快就解决了,昨天遇到这个错误当时看了大概10来分钟,还是没搞好,今天才来搞好了。

错误信息如下

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

上一篇: js history

下一篇: 头条二面