2020-12-27 、、 ManyResaultExption

2020-12-27
今日遭遇した問題

それはまだmybatisのクリーニングの問題であり、
とにかくドライバーをロードできません。ここでは、すべてのパッケージを削除し、プロジェクトを再インポートしてリファクタリングして問題を解決してください。

ManyResaultExption


構成されたSQLステートメントがselectAllによって実行され、すべてのクエリがオブジェクトとしてカプセル化されるため、ManyResaultExptionが再び問題になります。
したがって、返されるのは結果セット
です。受信するときは、コレクションオブジェクトとして受信する必要があります。コレクションタイプは、Beanに対応するタイプです。

<select id="selectAll" resultType="Bean.Student" >
        SELECT * FROM student
    </select>
    这里定义了语句,resultType定义了接收类型为Student

シーン1:

InputStream is = Resources.getResourceAsStream("MyBatiscConfig.xml");
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = build.openSession();       
        Student stu = sqlSession.selectOne("StudentMapper.selectAll");
        System.out.println(stu);
     用单个对象来接收,所以会出现MannyResault

シーン2:

  InputStream is = Resources.getResourceAsStream("MyBatiscConfig.xml");
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = build.openSession();
        List<Student> stu = sqlSession.selectOne("StudentMapper.selectAll");
        虽然这里使用的集合进行接收但是
        sqlSession却使用了错误的selectOne方法进行执行
        获取多个对象返回集合需要使用selectList方法执行
        否则依然会ManyResault 
        for (Student student : stu) {
    
    
            System.out.println(student);
        }

ここに画像の説明を挿入

おすすめ

転載: blog.csdn.net/m0_49194578/article/details/111823517