1. 程式人生 > >01_3_查詢指定id的單個對象

01_3_查詢指定id的單個對象

println line ram clas urn main ron center result

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]

01_3_查詢指定id的單個對象