问题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);
}