2017-07-07 49 views
1

如果沒有彈簧,一個MyBatis的映射器使用這樣的:如果使用spring來注入映射器,mybatis會話何時打開?

try (SqlSession session = sqlSessionFactory.openSession()) { 
    Mapper mapper = session.getMapper(Mapper.class); 
    result = mapper.select(...); 
} 
return result; 

在使用的彈簧,映射器使用這樣的:

@Inject 
private Mapper mapper; 

public Response work() { 
    result = mapper.select(); 
    return result; 
} 

我的問題是當在會話中打開?

回答

0

SqlSession由mybatis-spring提供的SqlSessionTemplate打開,它使用Spring Transaction管理機制在多個查詢上共享。

注意:SqlSessionTemplate使用JDK代理管理SqlSession的代理對象。