org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderExce

使用mybaties的@SelectProvider时出现的问题

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error invoking SqlProvider method (com.example.demo.dynamicsql.SqlProvider.selectCandidate).  Cause: org.apache.ibatis.binding.BindingException: Parameter 'arg0' not found. Available parameters are [id, param1]

上面是抛出的异常,就是找不到参数,我首先要生成一个动态sql,id默认为0,如果id为0,就查出所有数据,即不拼接where条件,若id不为0就查处对应的一条数据。新建一个和dao文件夹同级的pakage,里面的代码如下


然后我的dao层,代码为

 @SelectProvider(type = SqlProvider.class, method = "selectCandidate")
    @Results(id="candidateMap",value={
            @Result(property="id", column="id"),
            @Result(property="job", column="job"),
            @Result(property="salary", column="salary"),
            @Result(property="interviewTime", column="interview_time"),
            @Result(property="channel", column="channel"),
            @Result(property="name", column="name"),
            @Result(property="sex", column="sex"),
            @Result(property="nativePlace", column="native_place"),
            @Result(property="edu", column="edu"),
            @Result(property="peoples", column="peoples"),
            @Result(property="birthday", column="birthday"),
            @Result(property="domicile", column="domicile"),
            @Result(property="marriage", column="marriage"),
            @Result(property="politicalStatus", column="political_status"),
            @Result(property="address", column="addtress"),
            @Result(property="workAge", column="work_age"),
            @Result(property="phone", column="phone"),
            @Result(property="contracts", column="contracts"),
            @Result(property="contactsPhone", column="contracts_phone"),
            @Result(property="email", column="email"),
            @Result(property="qq", column="qq"),
            @Result(property="education", column="education"),
            @Result(property="work", column="work"),
            @Result(property="certificate", column="certificate"),
            @Result(property="skill", column="skill"),
            @Result(property="state", column="state"),
    })
    List<Candidate> selectCandidate(@Param("id")Integer id);

然后当我在动态sql类SqlProvider里面打断点,就发现无论把断点打着函数的哪个位置,断点都进不来,我开始怀疑是不是我的动态sql使用姿势错了,https://www.cnblogs.com/he-px/p/7134524.html,查看了这篇博客,我发现前端即便是传一个参数,sql类函数的参数也是map,然后从map里面过去想要的条件参数,于是我把SqlProvider这里里面对应函数的参数改成map。


这样就可以,可是为什么para的大小是2呢,我们查看debug控制台


然后去Dao那一层,我们试着将@Param那个参数删掉,然后我SqlProvider还原到参数是integer的样子,结果成功解决

阅读更多

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis

11-08

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: rn### Error querying database. Cause: java.lang.NullPointerExceptionrn### The error may exist in file [D:\apache-tomcat-7.0.63\webapps\SPM\WEB-INF\classes\com\bjhx\mapping\userMapper.xml]rn### The error may involve com.bjhx.dao.UsereMapper.jjrn### The error occurred while executing a queryrn### Cause: java.lang.NullPointerExceptionrn at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)rn at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)rn at com.sun.proxy.$Proxy14.selectOne(Unknown Source)rn at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:163)rn at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:68)rn at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)rn at com.sun.proxy.$Proxy15.jj(Unknown Source)rn at com.bjhx.service.impl.UserServiceImpl.jjl(UserServiceImpl.java:14)rn at com.bjhx.controller.UserController.testwwww(UserController.java:37)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)rn at java.lang.reflect.Method.invoke(Method.java:498)rn at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)rn at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)rn at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)rn at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)rn at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:690)rn at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)rn at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)rn at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)rn at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)rn at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)rn at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)rn at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)rn at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)rn at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)rn at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)rn at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)rn at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)rn at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)rn at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)rn at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)rn at java.lang.Thread.run(Thread.java:745)rnCaused by: org.apache.ibatis.exceptions.PersistenceException: rn### Error querying database. Cause: java.lang.NullPointerExceptionrn### The error may exist in file [D:\apache-tomcat-7.0.63\webapps\SPM\WEB-INF\classes\com\bjhx\mapping\userMapper.xml]rn### The error may involve com.bjhx.dao.UsereMapper.jjrn### The error occurred while executing a queryrn### Cause: java.lang.NullPointerExceptionrn at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)rn at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:111)rn at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)rn at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:66)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)rn at java.lang.reflect.Method.invoke(Method.java:498)rn at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)rn ... 44 morernCaused by: java.lang.NullPointerExceptionrn at java.lang.String.(String.java:166)rn at oracle.sql.CharacterSet.AL32UTF8ToString(CharacterSet.java:1517)rn at oracle.jdbc.driver.DBConversion.CharBytesToString(DBConversion.java:589)rn at oracle.jdbc.driver.DBConversion.CharBytesToString(DBConversion.java:542)rn at oracle.jdbc.driver.T4CTTIoauthenticate.receiveOauth(T4CTTIoauthenticate.java:816)rn at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:362)rn at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:414)rn at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:165)rn at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)rn at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)rn at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)rn at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294)rn at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1247)rn at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1221)rn at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)rn at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)rn at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)rn at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:81)rn at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:67)rn at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:279)rn at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:72)rn at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:59)rn at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)rn at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)rn at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)rn at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77)rn at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)rn ... 51 mrn这是为什么 我的myBatis一直报这个错误

没有更多推荐了,返回首页