第3讲 --查询指定id的单个对象
程序员文章站
2022-03-03 16:16:24
...
步骤:
1.增加 Student.xml中 对查找制定Id的单个对象的支持
<!-- parameterClass 指定参数的类型,#sid# 的写法是从外部等到参数值-->
<select id="selectStudentById" resultClass="Student" parameterClass="int">
select * from student where sid=#sid#
</select>
2.在实现类中
public Student selectStudentById(int sid)
{
Student student=null;
try
{
student=(Student)sqlMapClient.queryForObject("selectStudentById",sid);
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return student;
}
3.测试
StudentDAO studentDAO=new StudentDAOImpl();
Student student=studentDAO.selectStudentById(324);
log.info("姓名:"+student.getSname());
4.结果
422 [main] INFO cn.com.xinli.ibatis.dao.impl.StudentDAOImpl(101) - 姓名:你好
下一篇: Jupyter Notebook查看路径