在Student.xml中加入:

    <insert id="insertStudent" parameterClass="Student">
insert into student ( id , name , score )
values (#id#,#name#,#score#)
</insert>

并在junit中测试:

 1     @Test
2 public void addStudent() throws Exception{//新增学生
3 Reader reader=Resources.getResourceAsReader("SqlMapConfig.xml");//读取总配置文件
4 SqlMapClient sqlmapclient=SqlMapClientBuilder.buildSqlMapClient(reader);//创建SqlMapClient来操作数据库
5 reader.close();
6 Student student=new Student();
7 student.setId(5);
8 student.setName("Emily");
9 student.setScore(60);
10 sqlmapclient.insert("insertStudent",student);//调用我们写在xml中的sql语句
11 }

查看数据库:

ibatis基础(四):插入一个实体对象

新增成功




相关文章:

  • 2022-01-24
  • 2021-10-07
  • 2022-12-23
  • 2022-12-23
  • 2021-11-02
  • 2021-07-21
  • 2021-05-21
猜你喜欢
  • 2022-02-19
  • 2021-11-30
  • 2021-11-23
  • 2022-12-23
  • 2021-07-18
  • 2021-08-21
  • 2022-12-23
相关资源
相似解决方案