MyBatis - ResultHandler is not invoked

后端 未结 2 1266
长情又很酷
长情又很酷 2021-01-07 14:39

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

public interface CountryDirRdbMapper {
    publi         


        
2条回答
  •  一向
    一向 (楼主)
    2021-01-07 14:54

    Figured it out from pieces of information

    1. you need to get instance of SqlSession from your setup

      sqlSession = sqlSessionFactory.openSession();

    2. to use mapper with result handler, you need to make the mapper return void (important) and setup the result type for this mapper (important)

      @Select("select * from user") void selectAllUser(ResultHandler handler)

    3. get mapper from your sqlSession

      UserMapper mapper = sqlSession.getMapper(User.class);

    4. setup the session method with handler, the first parameter is the method name of the mapper you want to associate with your handler

      sqlSession.select("selectAllUser", yourResultHandler);

    5. start using your mapper

      mapper.selectAllUser(yourResultHandler);

    6. don't forget to release(close) session when done

提交回复
热议问题