A query was run and no Result Maps were found for...原來是mapper.xml文件出了問題,是使用MyBatis最常見的一種錯誤


今天遇到一個問題,原來是mapper.xml文件出了問題,是使用MyBatis最常見的一種錯誤

 

報錯的結果是這樣的:

 A query was run and no Result Maps were found for the Mapped Statement 'cn.zrgk.dao.RoleMapper.getRoleList'.  

  It's likely that neither a Result Type nor a Result Map was specified.
org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement 'cn.zrgk.dao.RoleMapper.getRoleList'. 
   It's likely that neither a Result Type nor a Result Map was specified. org.apache.ibatis.executor.resultset.FastResultSetHandler.validateResultMapsCount(FastResultSetHandler.java:177) org.apache.ibatis.executor.resultset.FastResultSetHandler.handleResultSets(FastResultSetHandler.java:150) org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:57) org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:70) org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:57) org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:259) org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:132) org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:105) org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606)

我的mapper.xml文件中有個查詢語句是這樣寫的:

   大家看看圖一,好像根本沒有錯誤,對嗎?再看看

 

  是的,沒錯,我沒有指定這個方法的返回類型,系統無法識別,於是就這樣改了一下,發現不報錯了

 

 

所以平時啊,我們要多多注意這些細節,更要去多加理解

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM