mybatis
请问各位大佬为啥会出现图片中的报错这是测试类的代码
import java.io.IOException;
import java.io.Reader;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import com.oracle.po.Student;
public class Test {
public static void main(String[] age) {
Student s=new Student();
s.setStudent_age(20);
s.setStudent_email("123@qq.com");
s.setStudent_id(123456);
s.setStudent_name("张三");
try {
//将主配置文件的内容读到一个 io。Reader中
Reader reader= Resources.getResourceAsReader("configuration.xml");
//使用mybatis的一个核心接口 SqlSessionFactory是SqlSession的工厂,生产SqlSession
SqlSessionFactory factory=new SqlSessionFactoryBuilder().build(reader);
//创建SqlSession对象 使用mybatis的SqlSession核心接口
SqlSession sqlsession= factory.openSession();
//调用sqlsession的insert方法执行SQL语句
sqlsession.insert("Student.insert",s);
sqlsession.commit();
} catch (IOException es) {
// TODO Auto-generated catch block
es.printStackTrace();
}
}
}
这是学生类的package com.oracle.po;
public class Student {
private int student_id;
private String student_name;
private String student_email;
private int student_age;
public int getStudent_id() {
return student_id;
}
public void setStudent_id(int student_id) {
this.student_id = student_id;
}
public String getStudent_name() {
return student_name;
}
public void setStudent_name(String student_name) {
this.student_name = student_name;
}
public String getStudent_email() {
return student_email;
}
public void setStudent_email(String student_email) {
this.student_email = student_email;
}
public int getStudent_age() {
return student_age;
}
public void setStudent_age(int student_age) {
this.student_age = student_age;
}
}
这是映射文件的
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="Student">
<insert id="insert1" parameterType="com.oracle.po.Student">
insert into student(student_id,student_name,student_email,student_age)
values(#{student_id},#{student_name},#{student_email},#{student_age})
</insert>
</mapper>
有鱼币报答 映射文件的id不是insert1吗? 授人以鱼不如授人以渔,建议博主自己根据提示的Exception定位到bug,然后自己先try解决,finally再去请教bigcow! 把映射文件中 <mapper namespace="Student">改成<mapper namespace="com.oracle.po.Student">
<insert id="insert1" parameterType="com.oracle.po.Student"> 改成<insert id="insert1" parameterType="Student">
试试 找到问题了,主配置文件中没定位映射文件
页:
[1]