鱼C论坛

 找回密码
 立即注册
查看: 4507|回复: 5

mybatis

[复制链接]
发表于 2021-2-8 23:27:07 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
请问各位大佬为啥会出现图片中的报错

这是测试类的代码
  1. import java.io.IOException;
  2. import java.io.Reader;

  3. import org.apache.ibatis.io.Resources;
  4. import org.apache.ibatis.session.SqlSession;
  5. import org.apache.ibatis.session.SqlSessionFactory;
  6. import org.apache.ibatis.session.SqlSessionFactoryBuilder;

  7. import com.oracle.po.Student;

  8. public class Test {
  9.         public static void main(String[] age) {
  10.                 Student s=new Student();
  11.                 s.setStudent_age(20);
  12.                 s.setStudent_email("123@qq.com");
  13.                 s.setStudent_id(123456);
  14.                 s.setStudent_name("张三");
  15.                 try {
  16.                         //将主配置文件的内容读到一个 io。Reader中
  17.                         Reader reader= Resources.getResourceAsReader("configuration.xml");
  18.                         //使用mybatis的一个核心接口 SqlSessionFactory是SqlSession的工厂,生产SqlSession
  19.                         SqlSessionFactory factory=new SqlSessionFactoryBuilder().build(reader);
  20.                         //创建SqlSession对象 使用mybatis的SqlSession核心接口
  21.                         SqlSession sqlsession= factory.openSession();
  22.                         //调用sqlsession的insert方法执行SQL语句
  23.                         sqlsession.insert("Student.insert",s);
  24.                         sqlsession.commit();
  25.                 } catch (IOException es) {
  26.                         // TODO Auto-generated catch block
  27.                         es.printStackTrace();
  28.                 }
  29.                
  30.         }

  31. }
复制代码


这是学生类的
  1. package com.oracle.po;

  2. public class Student {
  3.         private int student_id;
  4.         private String student_name;
  5.         private String student_email;
  6.         private int student_age;
  7.         public int getStudent_id() {
  8.                 return student_id;
  9.         }
  10.         public void setStudent_id(int student_id) {
  11.                 this.student_id = student_id;
  12.         }
  13.         public String getStudent_name() {
  14.                 return student_name;
  15.         }
  16.         public void setStudent_name(String student_name) {
  17.                 this.student_name = student_name;
  18.         }
  19.         public String getStudent_email() {
  20.                 return student_email;
  21.         }
  22.         public void setStudent_email(String student_email) {
  23.                 this.student_email = student_email;
  24.         }
  25.         public int getStudent_age() {
  26.                 return student_age;
  27.         }
  28.         public void setStudent_age(int student_age) {
  29.                 this.student_age = student_age;
  30.         }
  31.        

  32. }
复制代码


这是映射文件的
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

  5. <mapper namespace="Student">
  6.         <insert id="insert1" parameterType="com.oracle.po.Student">
  7.                 insert into student(student_id,student_name,student_email,student_age)
  8.                 values(#{student_id},#{student_name},#{student_email},#{student_age})
  9.         </insert>
  10.        
  11.        
  12. </mapper>
复制代码

@XJ%H9SZB5[1(L6]J}T@_T6.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-2-8 23:27:50 | 显示全部楼层
有鱼币报答
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-2-9 14:13:00 | 显示全部楼层
映射文件的id不是insert1吗?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-2-9 14:28:41 | 显示全部楼层
授人以鱼不如授人以渔,建议博主自己根据提示的Exception定位到bug,然后自己先try解决,finally再去请教bigcow!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-2-9 22:27:17 | 显示全部楼层
把映射文件中 <mapper namespace="Student">  改成<mapper namespace="com.oracle.po.Student">
<insert id="insert1" parameterType="com.oracle.po.Student"> 改成<insert id="insert1" parameterType="Student">

试试
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-2-17 02:42:20 | 显示全部楼层
找到问题了,主配置文件中没定位映射文件
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-15 12:27

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表