01_3_查询指定id的单个对象
1. 映射文件配置如下信息
<select id="selectStudentById" resultClass="Student" parameterClass="int">
select sid, name, major, birth, score from student where sid=#sid#
</select>
2. 实现类方法实现
public Student queryStudentById(int id) {
Student student = null;
try {
student = (Student) sqlMapClient.queryForObject("selectStudentById", id);
} catch (SQLException e) {
e.printStackTrace();
}
return student;
}
3. 测试及其结果
public static void main(String[] args) {
IStudentDAO dao = new IStudentDAOImpl();
/* for(Student student : dao.queryAllStudent()) {
System.out.println(student);
}
*/
System.out.println(dao.queryStudentById(1));
}
[sid:1, name:李明, major:语文, birth:Tue Mar 27 00:00:00 CST 2018, score:100.0]
原文地址:https://www.cnblogs.com/flyback/p/8660287.html
时间: 2024-11-09 07:53:05