简体   繁体   中英

How to connect a ResultHandler in MyBatis Mapper XML

I found several examples how to connect a custom ResultHandler to a MyBatis Query:

eg https://code.google.com/p/mybatis/wiki/ResultHandlerExample

Unfortunately the ResultHandler given in the example never gets invoked. (As the last comment already stated)

So I searched for a solution and found this: MyBatis - ResultHandler is not invoked

But this does not quite fit to my problem since I'm using MyBatis the xml-style way rather than the API-style way. So in my case I have no

SqlSession session = MyBatisConnectionFactory.getSqlSessionFactory().openSession(true);

Is there a way to connect my custom handler in the xml file, for example the <resultMap /> oder <select /> node?

You can define method with ResultHandler in your mapper:

public interface YourMapper {
    void getObjects(@Param("param1") Object param1, ResultHandler handler);
}

Then you can use it:

List<Object> getObjects(object param1) {
    YourResultHandler resultHandler = new YourResultHandler();
    yourMapper.getObjects(param1, resultHandler);
    return resultHandler.getResults();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM