第一种方式的ApplicationContext.xml
<bean id="userMapper" class="edu.cqupt.mapper.UserMapperImpl">
<property name="sqlSession" ref="sqlSession"/>
</bean>
第二种方式的ApplicationContext.xml
<bean id="userMapper" class="edu.cqupt.mapper.UserMapperImpl">
<property name="sqlSessionFactory" ref="sqlSessionFactory"/>
</bean>
- 继承 SqlSessionDaoSupport
- 使用getSqlSession()方法获得SqlSession
-
public class UserMapperImpl extends SqlSessionDaoSupport implements UserMapper {
public List<User> selectUser() {
UserMapper mapper = getSqlSession().getMapper(UserMapper.class);
return mapper.selectUser();
}
}