【问题标题】:MyBatis - ResultHandler is not getting called when no rows are returned by the select statementMyBatis - 当 select 语句没有返回任何行时,不会调用 ResultHandler
【发布时间】:2015-01-21 18:15:08
【问题描述】:

我正在使用 ibatis 会话 ResultHandler 流式传输 ResultSet。

我有自己的 ResultHandler 实现

public class StreamResultHandler<T> implements ResultHandler
{
    private JobType<T> job;

    public StreamResultHandler(ReplicatorType<T> replicatorType)
    {
        this.job = replicatorType;
    }

    @Override
    public void handleResult(ResultContext context)
    {
        T type = (T) context.getResultObject();
        job.callEndPointService(type);
    }
}

当我的 select 语句没有返回任何行时,mybatis 甚至没有调用 handleResult 方法。当没有返回行时,我想对数据库进行一些更新。

是否有指定行数的计数/标志?我怎样才能做到这一点。

我正在使用 mybatis-3.2.2。

感谢任何帮助。

提前致谢。

【问题讨论】:

  • 当没有行返回时为什么会被调用?它不正是你所期望的吗?没有结果 - 没有电话?

标签: mybatis mybatis-generator


【解决方案1】:

count 添加到您的StreamResultHandler 实现并在handleResult() 中增加它。处理的总结果将在count() 方法中提供,如下所述。

public class StreamResultHandler<T> implements ResultHandler
{
    private JobType<T> job;
    private int count;

    public StreamResultHandler(ReplicatorType<T> replicatorType)
    {
        this.job = replicatorType;
    }

    @Override
    public void handleResult(ResultContext context)
    {
        T type = (T) context.getResultObject();
        job.callEndPointService(type);
        count++;
    }

    public int count()
    {
        return count;
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-20
    • 1970-01-01
    • 1970-01-01
    • 2011-05-15
    • 1970-01-01
    • 2016-04-20
    • 1970-01-01
    相关资源
    最近更新 更多