ibatis基础(六):修改实体对象
在Student.xml中添加:
<update id="updateStudent" parameterClass="Student">
update student
set name=#name#,
score=#score#
where id=#id#
</update>
进行单元测试:
1 @Test
2 public void updateStudent() 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(1);
8 student.setName("Billy");
9 student.setScore(70.5f);
10 sqlmapclient.update("updateStudent",student);//调用我们写在xml中的sql语句
11 }
查看数据库: