栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

mybatis学习中遇见的bug

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

mybatis学习中遇见的bug

问题1:

报错·:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): org.example.dao.StudentDao.selectStudentById

 原因:在mapper文件中写接口方法时前面多加了一个空格。。

问题2:

报错:org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.apache.ibatis.reflection.ReflectionException: Error instantiating interface org.example.dao.StudentDao with invalid types () or values (). Cause: java.lang.NoSuchMethodException: org.example.dao.StudentDao.()
### The error may exist in org/example/dao/StudentDao.xml
### The error may involve org.example.dao.StudentDao.selectMultiParam
### The error occurred while handling results
### SQL: select id, name,email,age from student where name=? or age=?
### Cause: org.apache.ibatis.reflection.ReflectionException: Error instantiating interface org.example.dao.StudentDao with invalid types () or values (). Cause: java.lang.NoSuchMethodException: org.example.dao.StudentDao.()

 原因:

 在mapper文件中resultTypt导错文件了,应该导Student类。

问题3:在执行insert操作后IDEA中执行成功了,数据库中无结果

原因:少了提交事务这行代码。。。。需执行commit()方法

接口方法:

 int insertstu(Student student);

在映射文件中写sql语句:

 
        insert into student (id, name,email,age)
        values (#{id},#{name},#{email},#{age})
    

 在测试类中写测试方法:

 @Test
    public void testinsert(){
        SqlSession sqlSession=mybatisutils.getSqlSession();
        StudentDao dao=sqlSession.getMapper(StudentDao.class);
        Student student=new Student();
        student.setId(1007);
        student.setAge(90);
        student.setName("姜胜");
        student.setEmail("js.@qq.com");
        int kk=dao.insertstu(student);


        sqlSession.commit();
        sqlSession.close();
        System.out.println(kk);
    }


 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/356036.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号