MyBatis-不调用ResultHandler [英] MyBatis - ResultHandler is not invoked

查看:832
本文介绍了MyBatis-不调用ResultHandler的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循以下示例: https://code.google.com/p/mybatis /wiki/ResultHandlerExample 这是我的界面:

I followed this example : https://code.google.com/p/mybatis/wiki/ResultHandlerExample This is my interface:

public interface CountryDirRdbMapper {
    public static class CountryDirBaseItemWithText {
        public CountryDirBaseItem baseItem;
    }
    public List<CountryDirBaseItem> select(ResultHandler handler);
}

这是我的xml映射器

  <resultMap id="readItemsRM" type="CountryDirRdbMapper$CountryDirBaseItemWithText">
        <association property="baseItem" javaType="CountryDirBaseItem">
            <id property="id" column="Id"/>
            <result property="comment" column="Comment"/>
        </association>
    </resultMap>

此代码构成了我的DAO:

This code form my DAO:

SqlSession session = MyBatisConnectionFactory.getSqlSessionFactory().openSession(true);
List<CountryDirBaseItem> list;
  try{
       CountryDirRdbMapper mapper = session.getMapper(CountryDirRdbMapper.class);
       class MyResultHandler implements ResultHandler {
           @Override
           public void handleResult(ResultContext context) {
           System.out.println("#########################");
           }
       }

    MyResultHandler handler=new MyResultHandler();
      list= mapper.select(handler);
 }  
  finally {
   session.close();
}

但是,永远不会调用结果处理程序.在这个例子中,我跟随人们说有同样的问题.那么如何使其工作呢?还是mybatis 3不支持结果处理程序?

However the result handler is never invoked. At the example I follow people say that have the same problem. So how to make it work? Or result handler is not supported in mybatis 3?

推荐答案

我找到了答案.不幸的是,MyBatis开发人员根本不关心用户.他们真丢人.事实是,当我们使用自定义结果处理程序时,我们必须使用的不是接口,而是会话.

I found the answer. Unfortunately MyBatis developers don't care about users at all. Shame on them. The truth is when we use custom result handlers we must use not interface but session.

MyResultHandler handler=new MyResultHandler();
session.select("select", handler);

此后,必须从处理程序中获取结果.

After that the result must be taken from handler.

这篇关于MyBatis-不调用ResultHandler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆