Spring 的学习报错_____2.空指针异常 java.lang.NullPointerException

在进行 mybatis spring 整合中出现的,查明原因是因为在 UserMapperImpl中没有写接口方法的实现。

(使用UserMapperImpl的sqlSession属性)

实现如下:

public class UserMapperImpl implements UserMapper {

    //添加sqlSession属性
    private SqlSession sqlSession;

    public void setSqlSession(SqlSession sqlSession) {
        this.sqlSession = sqlSession;
    }

    public List<User> getUser() {

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

        return mapper.getUser();
        
    }
}

猜你喜欢

转载自www.cnblogs.com/xbfchder/p/11267221.html