01_3_查询指定id的单个对象

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]

 

posted @ 2018-03-27 21:18  FlyBack  阅读(147)  评论(0编辑  收藏  举报