sqlsession的创建由继承SqlSessionDaoSupport类来直接调用getsqlsession方法来实现
1 .实现类 2
package com.yyf.mapper;
import com.yyf.pojo.User;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import java.util.List;
public class userMapperImpl2 extends SqlSessionDaoSupport implements userMapper {
@Override
public List<User> selectUser() {
return getSqlSession ().getMapper (userMapper.class).selectUser ();
}
}
2.配置文件
因为当实现类继承了sqlsessiondaosupport,sqlsessiondaosupport里的sqlSessionTemplate
需要引入值,这时在给实现类创建bean的时候 引入上述配置文件sqlsessionfactory来给sqlsessiondaosupport类设置值
<bean id="usermapper2" class="com.yyf.mapper.userMapperImpl2">
<property name="sqlSessionFactory" ref="sqlSessionFactory"/>
</bean>
3.测试类以前的文件都有只要把bean对象换了就好了