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.<init>()
### 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.<init>()

 原因:

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

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

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

接口方法:

 int insertstu(Student student);

在映射文件中写sql语句:

 <insert id="insertstu" parameterType="org.example.domain.Student" >
        insert into student (id, name,email,age)
        values (#{id},#{name},#{email},#{age})
    </insert>

 在测试类中写测试方法:

 @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);
    }


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值