Mybatis:未找到映射语句的结果图

时间:2019-08-15 17:55:26

标签: mybatis

我必须向现有的映射器文件和代码中添加一个ping查询以确保db不会超时,如下所示:

在映射器XML中:

<select id="pingTest" statementType="CALLABLE">
    SELECT 1 FROM DUAL
</select>

接口:

void pingTest() throws SQLException;

实现(在LogInputDao类内部):

    public void pingTest() throws SQLException {
    SqlSession session = null;

    SqlSessionFactory sqlSessionFactory = MyBatisDBConfig.getSqlSessionFactory();

    session = sqlSessionFactory.openSession();

    LogInputMapper mapper = session.getMapper(LogInputMapper.class);
    mapper.pingTest();
}

logInputDao.pingTest()

找出错误:

### Error querying database.  Cause: org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement 'com.example.proj.name.dbservice.mappers.LogInputMapper.pingTest'.  It's likely that neither a Result Type nor a Result Map was specified.
### The error may exist in com/example/proj/dbservice/config/LogInputMapper.xml
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT 1 FROM DUAL
### Cause: org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement 'com.example.proj.name.dbservice.mappers.LogInputMapper.pingTest'.  It's likely that neither a Result Type nor a Result Map was specified.
        at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:95)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:59)
        at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:95)
        at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:40)
        at com.sun.proxy.$Proxy18.pingTest(Unknown Source)
        at com.example.proj.name.dbservice.dao.LogInputDao.pingTest(LogInputDao.java:52)
.....

我不需要结果,无论哪种方式,我不确定确切如何解决,这是我第一次使用MyBatis做某事

1 个答案:

答案 0 :(得分:0)

正如@ave上面已经说过的, 在select语句中,MyBatis期望返回一些数据,并且需要对其进行映射。 其中之一是必要的。 因此,您必须添加resultTyperesultMap标签,并删除不必要的statementType="CALLABLE"

以下是映射的示例:

<select id="pingTest" resultType="int">
    SELECT 1 FROM DUAL
</select>