01_5_删除指定id的单个对象
1. 配置相应的映射文件内容
<delete id="deleteStudent" parameterClass="int">
delete from student where sid=#sid#
</delete>
2. 实现类的方法
public void deleteStudentById(int id) {
try {
sqlMapClient.delete("deleteStudent", id);
} catch (SQLException e) {
e.printStackTrace();
}
}
3. 调试结果
public static void main(String[] args) {
IStudentDAO dao = new IStudentDAOImpl();
for(Student stu : dao.queryAllStudent()) {
System.out.println(stu);
}
//删除sid为7的数据
dao.deleteStudentById(7);
System.out.println("#############");
for(Student stu : dao.queryAllStudent()) {
System.out.println(stu);
}
}
[sid:7, name:fengge, major:null, birth:Tue Oct 05 00:00:00 CST 2010, score:110.0]
[sid:1, name:李明, major:语文, birth:Tue Mar 27 00:00:00 CST 2018, score:100.0]
[sid:2, name:可可, major:英语, birth:Mon Mar 12 00:00:00 CST 2018, score:120.0]
[sid:3, name:天天, major:数学, birth:Thu Mar 22 00:00:00 CST 2018, score:80.0]
#############
[sid:1, name:李明, major:语文, birth:Tue Mar 27 00:00:00 CST 2018, score:100.0]
[sid:2, name:可可, major:英语, birth:Mon Mar 12 00:00:00 CST 2018, score:120.0]
[sid:3, name:天天, major:数学, birth:Thu Mar 22 00:00:00 CST 2018, score:80.0]